第一种方法
// get OPTION elements for which `selected` property is true
$('option').not(function(){ return !this.selected })
问题
:$(‘option[selected]’) only finds options that have their selected attr set in the html.It does not find values the the user has selected themselves.
结论:
This is expected behavior. Such CSS selectors match attribute values, which don’t change with user interaction. Theselected property of the element changes, but attribute doesn’t.
第二种方法
$("#ID").val() 获取选中的value
$("#ID option").eq($("#ID").attr("selectedIndex")).text() 获取选中的文本值
本文介绍了两种使用jQuery获取<select>元素中用户所选项的方法。第一种通过筛选已选中的<option>元素;第二种直接利用.val()方法获取选中的值,并结合.eq()与.attr()方法获取选中文本。
168

被折叠的 条评论
为什么被折叠?



