使用jQuery获取所选的选项ID
我试图使用jQuery根据选定的选项进行ajax请求。
有没有简单的方法来检索使用jQuery选定的选项id (例如“id2”)?
<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 });  你可以使用:selectedselect器 ,如下所示: 
 $("#my_select").change(function() { var id = $(this).children(":selected").attr("id"); }); 
 var id = $(this).find('option:selected').attr('id'); 
 然后你用selectedIndex做你想做的 
我已经reedited我的答案…因为selectedIndex不是一个很好的variables给例子…
 $('#my_select option:selected').attr('id'); 
最简单的方法是var id = $(this).val(); 从一个像变化的事件里面。