当前位置: 编程技术>jquery
jquery实现Select option项的添加、删除、取值
来源: 互联网 发布时间:2014-09-03
本文导语: 1,获取Select选择的Text和Value: $("#s_id").change(function(){//code...}); //为Select添加事件,当选择其中一项时触发 var checkText=$("#s_id").find("option:selected").text(); //获取Select选择的Text var checkValue=$("#s_id").val(); //获取Select选择的Value var check...
1,获取Select选择的Text和Value:
$("#s_id").change(function(){//code...}); //为Select添加事件,当选择其中一项时触发 var checkText=$("#s_id").find("option:selected").text(); //获取Select选择的Text var checkValue=$("#s_id").val(); //获取Select选择的Value var checkIndex=$("#s_id ").get(0).selectedIndex; //获取Select选择的索引值 var maxIndex=$("#s_id option:last").attr("index"); //获取Select最大的索引值
2,添加/删除Select的Option项:
$("#s_id").append("Text"); //为Select追加一个Option(下拉项) $("#s_id").prepend("请选择"); //为Select插入一个Option(第一个位置) $("#s_id option:last").remove(); //删除Select中索引值最大Option(最后一个) $("#s_id option[index='0']").remove(); //删除Select中索引值为0的Option(第一个) $("#s_id option[value='3']").remove(); //删除Select中Value='3'的Option $("#s_id option[text='4']").remove(); //删除Select中Text='4'的Option
3,清空:
$("#charCity").empty();
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。