Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 在克隆select2的select事件上_Jquery_Jquery Select2_Jquery Select2 4 - Fatal编程技术网

Jquery 在克隆select2的select事件上

Jquery 在克隆select2的select事件上,jquery,jquery-select2,jquery-select2-4,Jquery,Jquery Select2,Jquery Select2 4,要在克隆的select2上侦听select2:select,我还需要执行哪些步骤 我尝试了.clone(true),$('.myclass')。选择2('destroy'),并使用$('#table tbody').hide().show(0)刷新DOM 基于此GitHub问题,这似乎是推荐的方法 $('.myclass')。选择2(); $('.myclass')。on('select2:select',函数(e){ 警报(“foo”); }); $('#addRow')。单击(函数(){

要在克隆的select2上侦听select2:select,我还需要执行哪些步骤

我尝试了
.clone(true)
$('.myclass')。选择2('destroy'),并使用
$('#table tbody').hide().show(0)刷新DOM

基于此GitHub问题,这似乎是推荐的方法

$('.myclass')。选择2();
$('.myclass')。on('select2:select',函数(e){
警报(“foo”);
});
$('#addRow')。单击(函数(){
$('#table tbody').append($('#table tbody tr:last').clone());
$('#表tbody tr:nth last child(2)select').addClass('myclass');
$('.myclass')。选择2();
});
。隐藏{
显示:无;
}

1.
2.
3.
1.
2.
3.
添加行
您可以将事件绑定到动态添加的元素

$('.myclass')。选择2();
$(文档).on('select2:select','.myclass',函数(e){
警报(“foo”);
});
$('#addRow')。单击(函数(){
$('#table tbody').append($('#table tbody tr:last').clone());
$('#表tbody tr:nth last child(2)select').addClass('myclass');
$('.myclass')。选择2();
});
。隐藏{
显示:无;
}

1.
2.
3.
1.
2.
3.
添加行

工作正常。谢谢你的链接和帮助。