2011-10-31 14 views
1

jqueryを使用してどの選択ボックスがデフォルトに設定されているかを調べようとしています。選択ボックスのデフォルト名を取得

私はこの多くの設定をしています。

これは私に各選択ボックスのデフォルト値を与えますが、これはどのオプションが属するのかを探そうとしています。

//Select every `<select>` which is a child of this.el, and loop through it 
var selectBoxes = $('select', this.el); 
selectBoxes.each(function(){ 
    //`this` points to the select element 
    // The following declaration will define a HTMLOptionElement 
    var selectedOption = select.options[this.selectedIndex]; 
    var value = selectedOption.value;  //Recommended 
    //Alternatively: $(selectedOption).val(); 
}); 

あなたが選択したオプション要素にjQueryのメソッドを使用する場合は、jQueryの中でオブジェクトをラップ:OPのコメントで私の答えをエラボレーション

+0

オプションを取得するには、 'select [i] .selectedIndex'と' select [i] .options [select [i] .selectedIndex] 'を使用します。 –

+0

ロブ、ありがとう、私が後になったことを解決しました。 – Chapsterj

答えて

0

それがあるべき..

var selectBoxes = $('select', this.el); 
selectBoxes.children().each(function(){ 
    console.log($(this).text()); 
}); 
0

コンストラクタ:$(selectedOption)

関連する問題