[英]add select2 class dynamically to current clicked element
我向当前单击的元素动态添加了select2类,但第二次单击后出现了搜索框。 它应该出现在元素上的第一次单击上。
例如:
$(document).on('click', 'select', function () {
$(this).select2();
});
谢谢
在select2初始化之后,我们可以使用命令.select2('open')
再次调用它。
希望这是您想要的。
$(document).on('click', 'select', function() { var select2_open; $(this).select2().select2('open'); });
<link href="https://select2.github.io/dist/css/select2.min.css" rel="stylesheet" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://select2.github.io/dist/js/select2.full.js"></script> <select class="select"> <option value="AL">Alabama</option> <option value="WY">Wyoming</option> </select>
$('.select').select2(); $(document).on('click', 'select', function() { $(this).select2(); });
<link href="https://select2.github.io/dist/css/select2.min.css" rel="stylesheet" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://select2.github.io/dist/js/select2.full.js"></script> <select class="select"> <option value="AL">Alabama</option> <option value="WY">Wyoming</option> </select>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.