$('#someId').prop('selectedIndex'); $('option:selected', '#someId').index(); $('#someId option').index($('#someId option:selected')) 以上三种方式可以取到索引值
假如你现在还在为自己的技术担忧,假如你现在想提升自己的工资,假如你想在职场上获得更多的话语权,假如你想顺利的度过35岁这个魔咒,假如你想体验BAT的工作环境,那么现在请我们一起开启提升技术之旅吧,详情请点击
案例应用
1 function checkBank() { 2 var industryParentType=$("#key_industryParentType").val(); 3 var accountName=$("#key_accountId option:selected").text(); 4 var Indexnnn=$('option:selected', '#key_accountId').index(); 5 alert(accountName+"---"+Indexnnn); 6 if(accountName.indexOf("快钱")>=0) { 7 if(industryParentType!=null&&industryParentType==3&&industryParentType!=""&&industryParentType!=undefined){ 8 alert("如果选择了金融行业,则在这里只能选择银行账户,如果没有银行账户请去银行账户页面添加银行账户,谢谢!"); 9 $("#key_accountId ").get(0).selectedIndex=2;10 11 }12 }13 }
默认选中第二条