-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を返す必要があります。これは、Webサイトがサイトを変更するまで機能していました。

私はかなりうるさくなることを知っていますが、これは拡張機能の開発のためのマニュアルであり、doc変数は必須ですhttp://www.allmangasreader.com/dev.phpgetInformationsFromCurrentPage関数に注意してください。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

常にフォールバックを使用し、attrを使用できます。このようにして、常に価値が得られることを保証できます。

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

http://jsfiddle.net/dt5PV/

于 2012-08-08T03:19:04.467 に答える
0
var curChapName = $("select.chapter_select:first :selected").text()
var chapurl = $("select.chapter_select:first").val()
于 2012-08-08T05:53:48.463 に答える