1

我已经搜索了 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);    
4

0 回答 0