2012-08-08 143 views
-4

我有一個網頁上這個網站:.VAL()選擇文本,而不是字符串值,當網頁dinamically編輯HTML源

<select name="chapter_select" class="chapter_select"> 
<option value="http://www.example.com/chapter/1">Chapter 1</option> 
<option value="http://www.example.com/chapter/2">Chapter 2</option> 
<option value="http://www.example.com/chapter/3">Chapter 3</option> 
<option value="http://www.example.com/chapter/4">Chapter 4</option> 
<option value="http://www.example.com/chapter/5">Chapter 5</option> 
<option value="http://www.example.com/chapter/6" selected="selected">Chapter 6</option> 
</select> 

而這個變量:

getInformationsFromCurrentPage : function(doc, curUrl, callback) { 
//This function runs in the DOM of the current consulted page 
var curChapName = $("select.chapter_select:first option:selected", doc).text(); 
var chapurl = $("select.chapter_select:first option:selected", doc).val(); 
callback({"name": name, 
     "currentChapter": curChapName, 
     "currentMangaURL": nameurl, 
     "currentChapterURL": chapurl}); 
}, 
} 

問題是否都返回相同的文本值。 chapurl應該返回url,而不是文本值。這一直在網站修改他們的網站。

我知道我會非常挑剔,但這是擴展的開發手冊,並且doc變量是必須的http://www.allmangasreader.com/dev.php只需查看getInformationsFromCurrentPage函數。它使用的是jQuery 1.4.2所以也許是這樣的,奇怪的是其他網站就是這樣工作的。

更新:服務器正在使用腳本(重寫html)讓我覺得下拉列表在頂部。我使用了一些選擇器來獲取源代碼之後的正確選擇。

+0

我得到的URL,如果我刪除的文檔對象:http://jsfiddle.net/fs49g/6/ – 2012-08-08 02:59:29

回答

0

總是可以使用回退並使用attr。這樣你就可以始終保證你會得到價值。

var chapval = $("select.chapter_select:first option:selected").attr('value'); 

http://jsfiddle.net/dt5PV/

+0

我試過了,不幸的是不工作,返回章節名稱,就像.val() – Braiam 2012-08-08 03:32:52

+1

@braiam如果這不起作用,我*保證*您確定要針對錯誤的下拉菜單,下一個列表(另一個發生在你定位的那個之前,所以它是':first'),或者服務器在通過html之前重寫你的標記瀏覽器。使用像螢火蟲這樣的工具來檢查'