【发布时间】:2016-09-19 19:33:54
【问题描述】:
我有一个表,其中有两个日期选择器,并且可以选择追加新行。 问题是当我添加新行时,日期选择器不起作用。
我创建了一个https://jsfiddle.net/3uhkeq1h/2/
<script>
$(document).ready(function () {
$('.txtDate22').datepicker({
changeMonth: true,
changeYear: true,
dateFormat: 'MM yy',
showButtonPanel: true,
onClose: function () {
var iMonth = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
var iYear = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
$(this).datepicker('setDate', new Date(iYear, iMonth, 1));
$(this).datepicker('refresh');
},
beforeShow: function () {
if ((selDate = $(this).val()).length > 0) {
iYear = selDate.substring(selDate.length - 4, selDate.length);
iMonth = jQuery.inArray(selDate.substring(0, selDate.length - 5), $(this).datepicker('option', 'monthNames'));
$(this).datepicker('option', 'defaultDate', new Date(iYear, iMonth, 1));
$(this).datepicker('setDate', new Date(iYear, iMonth, 1));
}
}
});
$(".txtDate22").focus(function () {
$(".ui-datepicker-calendar").hide();
$("#ui-datepicker-div").position({
my: "center top",
at: "center bottom",
of: $(this)
});
});
$(".txtDate22").blur(function () {
$(".ui-datepicker-calendar").hide();
});
});
</script>
【问题讨论】:
标签: jquery datepicker