down list (select box) using jQuery
This question already has an answer here:
因为$("#yourdropdownid option:selected")返回一个没有id属性的jQuery对象,所以可以使用.attr()来获取元素的id
$("#yourdropdownid option:selected").attr('id');
Get the id using .attr() or .prop() :
$("#yourdropdownid option:selected").prop('id')
or
$("#yourdropdownid option:selected").attr('id')
and if you want to use pure javascript then:
var obj=document.getElementById("myId").options[document.getElementById("myId").selectedIndex];
alert(obj.id);
Don't mix the jquery object with js property like $("#yourdropdownid option:selected").id .
上一篇: 如何从课堂上获得ID
下一篇: 下拉列表(选择框)使用jQuery
