jquery select 选中问题w

<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; 
     }});


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值