【发布时间】:2015-09-17 18:36:17
【问题描述】:
使用日期选择器进行克隆。我在 stackoverflow 中搜索了我的问题,但没有得到正确的东西。当用户单击原始日期的日期时,它按预期工作但是一旦用户单击克隆 div 中的 addmore 按钮,日期选择器就无法工作。我尝试给.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();
}
});
这里是小提琴link
提前致谢
【问题讨论】:
-
@Sushil 感谢您的帮助,但在克隆中我无法选择月份和年份的默认日期
-
这对你有用吗@Mahadevan?
-
感谢@Sushil 工作正常
标签: javascript jquery html datepicker