无法获取select2选择事件 [英] Cant get select2 select event to fire
问题描述
Hi
Thinking this should be so simple trying to execute a function when the selected event of JQuery select2 fires, but it doesn't fire, nothing at all in the console.
The select2 is on an aspx page on a formview, i hav removed it off the formviwew if for some reason it wasnt able to find it, exacctly the same nothing fires nothing in the console. Jquery is 3.3.1.
I am now out of ideas .....
Select2 version is 4.05, I have tried id=tagSelector" in place of name="tagSelector" I have also tried
<pre> <script >
$(document).ready(function () {
$(document).ready(function () {
$('#tagSelector').select2();
});
});
</script>
我尝试过:
< pre> HTML
隐藏复制代码
< select name =tagSelectormultiple =multiple>
< option value =Tag1> Tag1< / option>
< option value =Tag2> Tag2< / option>
< option value =Tag3 > Tag3< / option>
< option value =Tag4> Tag4< / option>
< option value =Tag5> Tag5< ; / option>
< option value =Tag6> Tag6< / option>
< / selec t>
JQuery
隐藏复制代码
< script>
$(document).ready(function(){
$('#tagSelector' ).select2();
});
< / script>
< script>
$(#tagSeletor)。on('change',function(){alert('hi'); });
//也尝试了下面的代码,就像在文档中一样(select2:select,对于V4
//$('#tagSelector').on(\"select2-select,function(e){
// alert('hello');
//});
< / script>
What I have tried:
<pre>HTML
Hide Copy Code
<select name="tagSelector" multiple="multiple">
<option value="Tag1">Tag1</option>
<option value="Tag2">Tag2</option>
<option value="Tag3">Tag3</option>
<option value="Tag4">Tag4</option>
<option value="Tag5">Tag5</option>
<option value="Tag6">Tag6</option>
</select>
JQuery
Hide Copy Code
<script >
$(document).ready(function() {
$('#tagSelector').select2();
});
</script>
<script>
$("#tagSeletor").on('change', function () { alert('hi'); });
// Have also tried the code below as in documentation even the on("select2:select", for V4
//$('#tagSelector').on("select2-select", function (e) {
// alert('hello');
//});
</script>
推荐答案
(document).ready(function() {
(document).ready(function () {
(document).ready(function(){
(document).ready(function () {
('#tagSelector')。select2();
}) ;
});
< / script>
('#tagSelector').select2(); }); }); </script>
我的尝试:
< pre> HTML
隐藏复制代码
< select name =tagSelectormultiple =multiple>
< option value =Tag1> Tag1< / option>
<选项值=Tag2> Tag2< / option>
< option value =Tag3> Tag3< / option>
< option value =Tag4 > TAG4< ; / option>
< option value =Tag5> Tag5< / option>
< option value =Tag6> Tag6< / option>
< / select>
JQuery
隐藏复制代码
< script>
What I have tried:
<pre>HTML
Hide Copy Code
<select name="tagSelector" multiple="multiple">
<option value="Tag1">Tag1</option>
<option value="Tag2">Tag2</option>
<option value="Tag3">Tag3</option>
<option value="Tag4">Tag4</option>
<option value="Tag5">Tag5</option>
<option value="Tag6">Tag6</option>
</select>
JQuery
Hide Copy Code
<script >
这篇关于无法获取select2选择事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!