我正在尝试使用 jQuery 根据所选选项发出 ajax 请求。
有没有一种简单的方法来检索所选的选项 ID(例如“id2”)使用 jQuery?
<select id="my_select">
<option value="o1" id="id1">Option1</option>
<option value="o2" id="id2">Option2</option>
</select>
$("#my_select").change(function() {
//do something with the id of the selected option
});
您可以使用:selected选择器 http://api.jquery.com/selected-selector/, 像这样:
$("#my_select").change(function() {
var id = $(this).children(":selected").attr("id");
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)