-4

我在网页上有这个 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)让我认为下拉列表在顶部。我使用了一些选择器来获取源代码之后的正确选择器。

4

3 回答 3

2
var curChapName = $("select.chapter_select:first option:selected", doc).text();
var chapurl = $("select.chapter_select:first option:selected", doc).val();

这项工作http://jsfiddle.net/所以你的 doc 变量一定有问题,请检查它

于 2012-08-08T02:59:40.463 回答
0
var curChapName = $("select.chapter_select:first :selected").text()
var chapurl = $("select.chapter_select:first").val()
于 2012-08-08T05:53:48.463 回答
0

总是可以使用后备并使用attr。这样,您始终可以保证您将获得价值。

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

http://jsfiddle.net/dt5PV/

于 2012-08-08T03:19:04.467 回答