克隆datepicker无效后的表格行

时间:2017-05-26 15:11:42

标签: jquery datepicker

我尝试克隆表行,它完全克隆了行,但是克隆行后datepicker无法正常工作,请帮我解决这个问题

我的代码是

<script src="plugins/bower_components/bootstrap-datepicker/bootstrap-datepicker.min.js"></script>

jQuery('.mydatepicker, #datepicker').datepicker();
jQuery('#datepicker-autoclose').datepicker({
    autoclose: true,
    todayHighlight: true
});

jQuery('#date-range').datepicker({
    toggleActive: true
});
jQuery('#datepicker-inline').datepicker({

    todayHighlight: true
});

scrip在图像中

enter image description here

datepicker脚本是

locationManager.requestState(for region: CLRegion)

1 个答案:

答案 0 :(得分:1)

必须在克隆的行输入上初始化datepicker。您应该使用委托事件和onfocus,如果您有很多行,这将更快。

来自docs:&#34;委托事件的优势在于它们可以处理来自稍后添加到文档的后代元素的事件。&#34;

jQuery 1.7+使用.on()

 $('table').on('focus', 'input.mydatepicker:not(.hasDatepicker)', function () {
    $('.mydatepicker').datepicker();
});

否则使用.bind()或.live()

<强>更新 这个班级有'theDatepicker&#39;可以添加到克隆的行中,因为它尚未初始化,所以应该删除。

工作fiddle

相关问题