ajaxを介してコンテンツを更新すると、日付ピッカーが失われることを除いて、私にとってはうまく機能するjQuery日付ピッカーがあります。私が言えることから、jQueryon()
を使用して入力にバインドする必要がありますが、バインドする適切なイベントが見つからないようです。
最初は機能しますが、その後の更新では機能しません:
$("[id^=startPicker]").datetimepicker({
showOn: "button",
buttonImage: "/img/calendar_icon.png",
buttonImageOnly: true,
dateFormat: 'mm/dd/yy',
timeFormat: 'hh:mm tt',
stepMinute: 1,
onClose: function (dateText, inst) {
var selectedDate = $(this).datepicker("getDate"); //Date object
$.ajax({
url: "/url",
dataType: "json",
method: 'post',
data: {
value: selectedDate.toDateString() + ' ' + selectedDate.toTimeString()
},
beforeSend: function () {
$("#loading").fadeIn();
},
success: function (data, textStatus) {
$("#content").html(data);
},
complete: function () {
$("#loading").fadeOut();
}
});
}
});
初回またはその後の更新ではバインドしません:
$('#content').on('ready', "[id^=startPicker]", function () {
$(this).datetimepicker({
showOn: "button",
buttonImage: "/img/calendar_icon.png",
buttonImageOnly: true,
dateFormat: 'mm/dd/yy',
timeFormat: 'hh:mm tt',
stepMinute: 1,
onClose: function (dateText, inst) {
var selectedDate = $(this).datepicker("getDate"); //Date object
$.ajax({
url: "/url",
dataType: "json",
method: 'post',
data: {
value: selectedDate.toDateString() + ' ' + selectedDate.toTimeString()
},
beforeSend: function () {
$("#loading").fadeIn();
},
success: function (data, textStatus) {
$("#content").html(data);
},
complete: function () {
$("#loading").fadeOut();
}
});
}
});
});