jquery select 选中问题w

来源:互联网 发布:华润网络福利待遇 编辑:程序博客网 时间:2024/06/05 19:43

<body><div class="memberd main">   <div class="memberrd">    <div class="setupd"> <div class="memformd setauthd">  <div class="row zyfw">    <div id="businessScopeContent"  style="margin-left: 215px;">    <select id="business_scope" name="business_scope" class="sel w3" style="width: 157px;">            <option value="">--请选择主营范围--</option>           <option value="1">heheh</option><option value="2">heheh1</option><option value="3">heheh2</option><option value="4">heheh3</option>            </select></div>   </div></div> </div>   </div>  </div></body>


$("#business_scope option[value='1']").attr("selected", true); //是能把value 为1的选项设置为选择

$("#business_scope option[text='heheh']").attr("selected", true);//是不能把text = 'heheh' 的选项选中

$("#business_scope option:contains('heheh2')").attr('selected', true);//是可以把text = 'heheh2' 的选项选中 但是把所有 包含'heheh2的值都会命中,代替的代码可以这样:

$("#business_scope option:contains('heheh')").map(function(){        if ($(this).text() == "heheh1") {      $(this).attr('selected', true);            //return this;      }});


原创粉丝点击