
*** 作步骤:
“$(".selector").val("pxx")”。
设置text为pxx的项选中
“$(".selector").find("option[text='pxx']").attr("selected",true)”。
3、获取当前选中项的value“$(".selector").val()”。
4、获取当前选中项的text“$(".selector").find("option:selected").text()”。
你好!!
//可以通过以下方式设置//通过返回dom对象,设置"选中索引"属性的方式
$("#sel")[0].selectedIndex = 0
//直接使用eq()定位option,通过prop()方式,设置选中状态
$("#sel option").eq(2).prop("selected",true) function test(num){
$("#sel")[0].selectedIndex = num
$("#sel option").eq(num).prop("selected",true)
}
希望对你有帮助!!
你方式不正确 你那个是赋值,你把代码贴出来 还有 你需要循环获取每个option才能改selected ,
<select id="sel"><option value="一类">一类</option>
<option value="二类">二类</option>
<option value="三类">三类</option>
</select>
<script>
$("#sel option").each(function() {
if($(this).val()=='二类'){
$(this).prop('selected',true)
}
})
</script>
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)