jquery select 选中问题w

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sonycong/article/details/72178838

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


猜你喜欢

转载自blog.csdn.net/sonycong/article/details/72178838
今日推荐