Jquery检查是不是选择了选择框[重复]
Posted
技术标签:
【中文标题】Jquery检查是不是选择了选择框[重复]【英文标题】:Jquery check if select box is selected [duplicate]Jquery检查是否选择了选择框[重复] 【发布时间】:2015-07-05 23:04:21 【问题描述】:我有 3 个选择框:
<div class="widget mm_select">
<label for="ctrl_Customers_Region">Region</label> <select name="Customers_Region" id="ctrl_Customers_Region" class="select"><option value="">No filtering</option><option value="emea" selected="">EMEA</option><option value="america">America</option><option value="apac">APAC</option><option value="global">Global</option></select></div>
<div class="widget mm_select ">
<label for="ctrl_Customers_Branche">Business</label> <select name="Customers_Branche" id="ctrl_Customers_Branche" class="select"><option value="">No filtering</option><option value="retail-fashion">Retail - Fashion</option><option value="retail-consumer-electronics">Retail - Consumer Electronics</option><option value="retail-digital-goods">Retail - Digital Goods</option><option value="retail-furniture">Retail - Furniture</option><option value="retail-other">Retail - Other</option><option value="manufacturing-automotive">Manufacturing - Automotive</option><option value="manufacturing-pharmaceuticals-chemicals">Manufacturing - Pharmaceuticals / Chemicals</option><option value="manufacturing-high-tech">Manufacturing - High-Tech</option><option value="manufacturing-other">Manufacturing - Other</option><option value="utilities-and-telco-utilities">Utilities and Telco - Utilities</option><option value="utilities-and-telco-telco">Utilities and Telco - Telco</option><option value="food-grocery-and-equipment">Food - Grocery and Equipment</option><option value="media-entertainment-and-publishing">Media, Entertainment, and Publishing</option><option value="b2b-and-distribution">B2B and Distribution</option></select></div>
如何检查是否选择了 3 个选择框?
谢谢
【问题讨论】:
$('select').is(':has(option[value!=""]:selected)')
【参考方案1】:
您可以找到已选择且没有值“”的选项:
if($('select option:selected[value!=""]').length )
//more than one select box is selected
【讨论】:
谢谢,这个脚本是否适用于所有 3 个选择框? 选择器是全局的。所以是的。 酷,我试过这个,但它在 Firefox 中不起作用: if($('select option:selected[value!=""]').length ) $('body' ).animate( scrollTop: parseInt($(".ce_metamodels_frontendfilter").offset().top -320) , 2000); 你能创建相同的小提琴吗??以上是关于Jquery检查是不是选择了选择框[重复]的主要内容,如果未能解决你的问题,请参考以下文章
使用jQuery从下拉列表(选择框)中获取选定的ID [重复]