我有一个选择菜单,我正在尝试绑定点击功能,并且能够在更改时重新获得选择选项值属性。
select = $('#select_networks').selectmenu();
//bind the change of network/group
select.bind( "change", function(event, ui) {
//need to figure out the selected elements value attribute
});
答案 0 :(得分:2)
见:
$("#select_networks").bind("change", function() {
alert($(this).val());
});
<强>更新强>
$("#select_networks").bind("change", function() {
var typeVal = $(this).children("*[value=" + $(this).val() + "]").attr("type");
alert(typeVal);
});
答案 1 :(得分:1)
this.value
通常你可以将它与表单元素一起使用,它比将this
包装为jQuery对象然后提取值要快得多。
但是在某些情况下,特别是在select的情况下,当没有明确value=""
的选项时,你可以在旧版本的IE中遇到问题,而jquery会为你解决这个问题......
$(this).val();
答案 2 :(得分:1)
select.bind( "change", function(event, ui) {
$(this).children(':selected').val();
});
这将选择所选的<option>
。