SELECTタグ値を取得 var value = $('#select1').val();
// または
var value = $('#select1 option:selected').val();
値を設定 $('#select1').val('ABC');
選択されたOPTIONタグを取得 var option = $('#select1 otpion:selected');
全てのOPTIONタグを取得 var opts = [];
$('#select1 option').each(function(){
opts.push($(this));
});
selectedIndexを取得(設定)する var num = $('#select1').prop('selectedIndex');
$('#select1').prop('selectedIndex', 0);
attr()よりもprop()を使った方が良い。 参考 |
|