Mah*_*van 3 html javascript jquery datepicker
使用datepicker处理克隆.我在stackoverflow中搜索了我的问题我没有得到正确的东西.当用户单击原始日期的日期时,它按预期工作但是一旦用户单击克隆div中的addmore按钮,则datepicker无法正常工作.我试着给.destroy结果没有达到预期.这可能是重复的问题,但正如我所说的解决方案不适合我的情况.
这是jquery代码.
var currentDate = new Date();
$(".cloned-row1").find(".deg_date").removeClass('hasDatepicker').datepicker({
dateFormat: "mm-dd-yy",
changeMonth: true,
yearRange: "-100:+0",
changeYear: true,
maxDate: new Date(),
showButtonPanel: false,
beforeShow: function () {
setTimeout(function (){
$('.ui-datepicker').css('z-index', 99999999999999);
}, 0);
}
});
$(".deg_date").datepicker("setDate", currentDate);
var count=0;
$(document).on("click", ".edu_add_button", function () {
alert("checj");
var $clone = $('.cloned-row1:eq(0)').clone(true,true);
//alert("Clone number" + clone);
$clone.find('[id]').each(function(){this.id+='someotherpart'});
$clone.find('.btn_more').after("<input type='button' class='btn_less1' id='buttonless'/>")
$clone.attr('id', "added"+(++count));
$clone.find(".school_Name").attr('disabled', true).val('');
$clone.find(".degree_Description").attr('disabled', true).val('');
$clone.find("input.deg_date").datepicker();
$(this).parents('.educat_info').after($clone);
});
$(document).on('click', ".btn_less1", function (){
var len = $('.cloned-row1').length;
if(len>1){
$(this).closest(".btn_less1").parent().parent().parent().remove();
}
});
Run Code Online (Sandbox Code Playgroud)
这是小提琴链接
提前致谢
Jquery datepicker为初始化时绑定的输入字段创建基于UUID的ID属性.克隆这些元素会导致更多元素具有相同的ID(jQuery不喜欢),或者如果克隆例程管理它,则会产生不同的ID(这意味着datepicker不知道克隆).
尝试像这样更新你的js代码
$clone.find("input.deg_date")
.removeClass('hasDatepicker')
.removeData('datepicker')
.unbind()
.datepicker({
dateFormat: "mm-dd-yy",
changeMonth: true,
yearRange: "-100:+0",
changeYear: true,
maxDate: new Date(),
showButtonPanel: false,
beforeShow: function() {
setTimeout(function() {
$('.ui-datepicker').css('z-index', 99999999999999);
}, 0);
}
});
Run Code Online (Sandbox Code Playgroud)
这是更新的JSFIDDLE.希望这可以帮助.