如何从jQuery选择选择下拉菜单中隐藏或删除选项 [英] How to hide or remove options from jQuery Chosen select dropdown
问题描述
我想从使用选择的"插件创建的下拉菜单中隐藏某些元素.
I would like to hide certain elements from a dropdown that is created using the Chosen plugin.
我尝试将其删除:
$( 'option:contains("Swatch 1")').remove().trigger("chosen:updated");
并隐藏它:
$( '.chosen-results li:contains("Swatch 1")').css('display,'none');
但都行不通.
请参阅颜色"下拉列表: http://www.carolineelisa.com/test/wordpress /product/machine/
See Colours dropdown: http://www.carolineelisa.com/test/wordpress/product/machine/
任何帮助表示赞赏:)
推荐答案
在原始选择中,您需要隐藏该选项.例如:
In the original select you need to hide the option. For example:
$('select.chosen-select options:contains("Swatch 1")');
然后使用以下命令更新所选选项:
Then update the chosen options with:
$('select.chosen-select').trigger("chosen:updated");
如果您在页面上选择了多个下拉菜单,那么最好在该元素上使用更具体的ID或类代替$('select.chosen-select').因此您的代码将变为:
If you have more than one chosen drop down on the page then it probably would be better to use a more specific id or class on that element in the place of $('select.chosen-select'). So your code would become:
$('#swatch_select options:contains("Swatch 1")');
$('#swatch_select').trigger("chosen:updated");
这篇关于如何从jQuery选择选择下拉菜单中隐藏或删除选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!