开通VIP,畅享免费电子书等14项超值服
首页
好书
留言交流
下载APP
联系客服
2014.08.06
分享下JQuery如何设置获取下拉菜单某个选项的值,多种方法,值得收藏。
JQuery获取和设置Select选项
获取Select :获取select 选中的 text :$(“#ddlRegType”).find(“option:selected”).text();获取select选中的 value:$(“#ddlRegType “).val();获取select选中的索引:$(“#ddlRegType “).get(0).selectedIndex;设置select:设置select 选中的索引:$(“#ddlRegType “).get(0).selectedIndex=index;//index为索引值设置select 选中的value:$(“#ddlRegType “).attr(“value”,”Normal“);$(“#ddlRegType “).val(“Normal”);$(“#ddlRegType “).get(0).value = value;设置select 选中的text:var count=$(“#ddlRegType option”).length;for(var i=0;i<count;i++){ if($(“#ddlRegType “).get(0).options[i].text == text){ // www.jbxue.com$(“#ddlRegType “).get(0).options[i].selected = true;break;}}清空 Select:$(“#ddlRegType “).empty();
微信登录中...请勿关闭此页面