[英]jQuery chosen-select prevent hiding of select
I want to hide a select with the chosen-select class applied if it has no elements except it doesn't work. 如果没有元素,我想隐藏一个选择选择类的选择,除非它不起作用。
Ive tried 我试过了
$("#Category2").hide();
and then removing the chosen-select class prior to hide attempt: 然后在隐藏尝试之前删除所选的选择类:
$("#Category2").remove("chosen-select");
$("#Category2").hide();
but neither approach works. 但这两种方法都不奏效 If I don't do: 如果我不这样做:
$(".chosen-select").chosen();
then the select will hide. 然后选择将隐藏。 Also no errors in Chrome Developer tools console. Chrome Developer工具控制台中也没有错误。
Is this a known issue? 这是一个已知的问题? Is there a "trick" to doing this? 这样做有“技巧”吗?
Chosen creates additional elements - try $("#Category2_chosen").hide();
选择创建其他元素 - 尝试$("#Category2_chosen").hide();
. 。 See it work: http://jsfiddle.net/lhoeppner/9UB23/ 看到它的工作: http : //jsfiddle.net/lhoeppner/9UB23/
Edit for further explanation: 编辑以获得进一步说明
Try using your browser's development tools to inspect the DOM elements (usually right-click on the element, then "Inspect element" or similar). 尝试使用浏览器的开发工具来检查DOM元素(通常右键单击元素,然后“Inspect element”或类似元素)。
You'll see that once you call $(element).chosen()
on a DOM element, the following things happen: 你会看到,一旦你在DOM元素上调用$(element).chosen()
,就会发生以下情况:
style="display: none;"
) 原始元素是隐藏的(它仍然在DOM中,但是style="display: none;"
) chosen-container
and an id which is derived from the element's id (in this case by appending "_chosen" to it) 所选择的下拉窗口小部件是使用许多其他DOM元素创建的,这些元素都被分组为class selected chosen-container
的div和从元素的id派生的id(在这种情况下通过附加“_chosen”) The underscore doesn't have any special meaning, it's simply chosen's way of creating another unique id. 下划线没有任何特殊含义,它只是选择创建另一个唯一ID的方式。 It could just as append "-chosen" or "_mycustomsuffix". 它可以附加“-chosen”或“_mycustomsuffix”。
$("select#chosen-select").hide()
应该做的伎俩。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.