我搜索过SO并搜索了一个关于克隆div的解决方案,其中一个包含jQuery Datepicker。我尝试了几次尝试修改“新”克隆代码,但结果为负面。如果有人能够看一眼并指出我正确的方向,我将非常感激。
如果您需要其他信息,则无问题。enter code here
提前致谢, 千斤顶
$(document).ready(function(){
$('.my_date').datepicker({ //Datepicker
dateFormat: 'mm-dd-y',
});
$('#clonetrigger').click(function(){
var yourclass=".clonable";
var clonecount = $(yourclass).length;
var newid = Number(clonecount) + 1;
$(yourclass+":first").fieldclone({
newid_: newid,
target_: $("#formbuttons"),
insert_: "before",
limit_: 4
});
return false;
});
});
//The Plugin Script
(function($) {
$.fn.fieldclone = function(options) {
//==> Options <==//
var settings = {
newid_ : 0,
target_: $(this),
insert_: "before",
limit_: 0
};
if (options) $.extend(settings, options);
if( (settings.newid_ <= (settings.limit_+1)) || (settings.limit_==0) ){
//==> Clone <==//
var fieldclone = $(this).clone();
var node = $(this)[0].nodeName;
var classes = $(this).attr("class");
//==> Increment every input id <==//
var srcid = 1;
$(fieldclone).find(':input').each(function(){
var s = $(this).attr("name");
$(this).attr("name", s.replace(eval('/_'+srcid+'/ig'),'_'+settings.newid_));
});
//==> Locate Target Id <==//
var targetid = $(settings.target_).attr("id");
if(targetid.length<=0){
targetid = "clonetarget";
$(settings.target_).attr("id",targetid);
}
//==> Insert Clone <==//
var newhtml = $(fieldclone).html().replace(/\n/gi,"");
newhtml = '<'+node+' class="'+classes+'">'+newhtml+'</'+node+'>';
eval("var insertCall = $('#"+targetid+"')."+settings.insert_+"(newhtml)");
newSection.find(".my-date").datepicker(); //Datepicker
}
};
})(jQuery);