jquery操作select

获取select 的text值:

$('#testSelect option:selected').text();

获取select 的value值:

$('#testSelect').val();

$("#testSelect' ").get(0).selectedIndex; //获取Select选择的索引值

 

 

1、设置value为pxx的项选中

     $("#testSelect ").val("pxx");

2、设置text为pxx的项选中

    $("#testSelect ").find("option[text='pxx']").attr("selected",true);

 

加下拉选项

$("#testSelect'").append("<option value='Value'>Text</option>"); //追加到最后
$("#testSelect'").prepend("<option value='0'>请选择</option>"); //加到最前面

 

删除选项

$("#testSelect'").empty();  //清空
$("#testSelect' option:last").remove(); //保留最后一项,删除其他的
$("#testSelect' option:not(:first)").remove();//保留第一项,删除其他的
$("#testSelect' option[index='0']").remove();   //删除Select中索引值为0的Option(第一个)
$("#testSelect' option[value='3']").remove();   //删除Select中Value='3'的Option
$("#testSelect' option[text='4']").remove();   //删除Select中Text='4'的Option

 

posted @ 2014-09-12 10:24  H辉  阅读(130)  评论(0编辑  收藏  举报