标题: jquery Select操作大集合 [打印本页]
作者: xiexie 时间: 2012-7-20 17:29 标题: jquery Select操作大集合
jQuery获取Select选择的Text和Value:
语法解释:
- $("#select_id").change(function(){
- var checkText=$("#select_id").find("option:selected").text();
- var checkValue=$("#select_id").val();
- var checkIndex=$("#select_id ").get(0).selectedIndex;
- var maxIndex=$("#select_id option:last").attr("index");
语法解释:
- $("#select_id ").get(0).selectedIndex=1;
- $("#select_id ").val(4);
- $("#select_id option[text='jQuery']").attr("selected", true);
-
-
jQuery添加/删除Select的Option项:
语法解释:
- $("#select_id").append("<option value='Value'>Text</option>");
- $("#select_id").prepend("<option value='0'>请选择</option>");
- $("#select_id option:last").remove();
- $("#select_id option[index='0']").remove();
- $("#select_id option[value='3']").remove();
- $("#select_id option[text='4']").remove();
欢迎光临 PHP开发笔记 (http://phpvi.com/) |
Powered by Discuz! 6.1.0 |