1. 获取Select
获取select 选中的 text :
$("#selectname").find("option:selected").text();获取select选中的 value:
$("#selectname").val();获取select选中的索引:$("#selectname").get(0).selectedIndex;2. 设置select
设置select 选中的索引:
$("#selectname ").get(0).selectedIndex=index;//index为索引值设置select 选中的value:
$("#selectname").attr("value","Normal“);$("#selectname").val("Normal");$("#selectname").get(0).value = value;设置select 选中的text:
var count=$("#selectname option").length; for(var i=0;i<count;i++) { if($("#selectname").get(0).options[i].text == text) { $("#selectname").get(0).options[i].selected = true; break; } } $("#select_id option[text='jQuery']").attr("selected", true);设置select option项:
$("#select_id").append("<option value='Value'>Text</option>"); //添加一项option$("#select_id").prepend("<option value='0'>请选择</option>"); //在前面插入一项option$("#select_id option:last").remove(); //删除索引值最大的Option$("#select_id option[index='0']").remove();//删除索引值为0的Option$("#select_id option[value='3']").remove(); //删除值为3的Option$("#select_id option[text='4']").remove(); //删除TEXT值为4的Option
获取select 选中的 text :
$("#selectname").find("option:selected").text();获取select选中的 value:
$("#selectname").val();获取select选中的索引:$("#selectname").get(0).selectedIndex;2. 设置select
设置select 选中的索引:
$("#selectname ").get(0).selectedIndex=index;//index为索引值设置select 选中的value:
$("#selectname").attr("value","Normal“);$("#selectname").val("Normal");$("#selectname").get(0).value = value;设置select 选中的text:
var count=$("#selectname option").length; for(var i=0;i<count;i++) { if($("#selectname").get(0).options[i].text == text) { $("#selectname").get(0).options[i].selected = true; break; } } $("#select_id option[text='jQuery']").attr("selected", true);设置select option项:
$("#select_id").append("<option value='Value'>Text</option>"); //添加一项option$("#select_id").prepend("<option value='0'>请选择</option>"); //在前面插入一项option$("#select_id option:last").remove(); //删除索引值最大的Option$("#select_id option[index='0']").remove();//删除索引值为0的Option$("#select_id option[value='3']").remove(); //删除值为3的Option$("#select_id option[text='4']").remove(); //删除TEXT值为4的Option
![](http://hiphotos.baidu.com/__%BF%D5%B0%D7_/pic/item/f3cccb2f09f7905229515f700cf3d7ca7acbd5a3.jpg?v=tbs?v=tbs)