2012-08-08 153 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之前重写你的标记浏览器。使用像萤火虫这样的工具来检查'