admin管理员组文章数量:1328033
I'm using the jquery select2 plugin but I want to disable it for certain select dropdowns. Is there a way to exclude select elements the plugin will be applied to? I was thinking maybe a class on the select element to tell the plugin to ignore it.
I'm using the jquery select2 plugin but I want to disable it for certain select dropdowns. Is there a way to exclude select elements the plugin will be applied to? I was thinking maybe a class on the select element to tell the plugin to ignore it.
Share Improve this question asked May 1, 2015 at 15:36 steven35steven35 4,0176 gold badges39 silver badges49 bronze badges4 Answers
Reset to default 6$('select').not('.yourExcludeClass').select2();
Here's a link to the docs for $.not()
While just not calling .select2()
on the elements which you don't want to be dropdown works, you might want to disable Select2 after you've already initialized it.
In order to do this, you have two options
- Visually disable it like you would a standard
<select>
by calling$("select").prop("disabled", true)
. - "Destroy" Select2 so it goes back to looking like a standard dropdown by calling
$("select").select2("destroy")
.
You can disable it using -
$('select').select2("enable",false);
using JQuery.
I am assuming you are applying it to all selects via:
<script type="text/javascript">
$('select').select2();
</script>
There are a few ways you could solve it, but the easiest would be to add a class to the selects you want to be styled And only call the select2()
on those:
- Add the class
addStyling
to your selects to be styled - Initialize them with
$('select.addStyling').select2();
本文标签: javascriptHow can I disable the select2 plugin for certain select dropdownsStack Overflow
版权声明:本文标题:javascript - How can I disable the select2 plugin for certain select dropdowns? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742244451a2439039.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论