select2复制下拉框clone

select2正常复制,会多一个框出来,我的解决办法:

function cloneSelect2(){
	var soruSelect = $("#sourceTable tbody").find("select[name='sourceSelect']");//1.要copy的对象
	sourceSelect.select2('destroy'); //2.copy之前,要copy的对象重置
	$("#targetTableName tbody").append($("#sourceTable tbody tr").clone());//3.将对象tr copy 到目标表最后一行
	var tagertSelect = $($("#targetTableName tr:last").find("select[name='sourceSelect']"));   //4.copy后,得到copy后的对象
	tagertSelect.select2('destroy'); //6.copy后的对象重置
	this.initSelect2(tagertSelect); //6.初始化
	tagertSelect.select2();//7.加载
}

initSelect2:function($elem) { //初始化
        $elem.select2({
            minimumResultsForSearch: -1,
            width: 'resolve'
        });   
    },


 
  

你可能感兴趣的:(jquery)