<select name=’sel’ id=’sel’>
<option value=’1′>1</option>
<option value=’2′ selected=’selected’>我被选中了</option>
<option value=’3′>2</option>
</select>
<script>
alert($("select[@name='sel'] option[@selected]").text());
$("#sel").val(’2′);
alert($("select[@name='sel'] option[@selected]").text());
</script>

查询被选中的option中的内容当然也可以用 alert($("#sel option[@selected]").text());

稍微解释一下:
select[@name='sel'] option[@selected] 表示具有name 属性,并且该属性值为’sel’ 的select元素 里面的具有selected 属性的option 元素;可以看出有@开头的就表示后面跟的是属性。

相关文章:

  • 2022-01-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-12
  • 2021-12-23
猜你喜欢
  • 2021-07-22
  • 2021-06-12
  • 2021-09-01
  • 2022-01-02
  • 2022-12-23
相关资源
相似解决方案