js操作select

select获取选中值

  第一种方式

$('#testSelectoption:selected').text();//选中的文本

$('#testSelect option:selected').val();//选中的值

$("#testSelect").get(0).selectedIndex;//索引

 

    第二种方式
$("#tesetSelect").find("option:selected").text();//
选中的文本
$("#tesetSelect").find("option:selected").val();选中的值
$("#tesetSelect").find("option:selected").get(0).selectedIndex;索引

 

动态添加select中的option选项

  var optionObj =document.createElement("option");

   optionObj.value =zyxmxx[i].ZYJGXMBH;

   optionObj.text =zyxmxx[i].ZYJGXMMC;

dom添加: 

document.getElementById("txt_JSYDMC").options.add(optionObj);

jquery添加

$("#" +divID).get(0).options.add(optionObj);

select清空

 方法1:$("#txt_JSYDMC").empty();

 方法2:

 var o = document.getElementById("dll_TableName");

 o.length =0;

jquery动态设置select选中

红色字体部分为控件的id

for (var j = 0; j <$("#sel_exFieldType_"+ i + " option").length; j++) {

if ($("#sel_exFieldType_" + i + " option").get(j).value ==sc.SelectCondition[i].ExType) {

  $("#sel_exFieldType_" + i + "option").get(j).selected= true;

           };

       }

Jquery跟据index设置选中值 

 /*设置select选中值  */
        $("select[name='project.customerId']").get(0).selectedIndex=hideSelectValindex;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值