JQuery操作Select下拉列表


<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 元素;可以看出有@开头的就表示后面跟的是属性。