我有2个日期选择器来计算它们之间的天数:
$(function() {
$("#datepicker2").datepicker();
$("#datepicker3").datepicker({
onSelect: showDays
});
});
function showDays() {
var start = $('#datepicker2').datepicker('getDate');
var end = $('#datepicker3').datepicker('getDate');
if (!start || !end)
return;
var days = (end - start) / 1000 / 60 / 60 / 24;
$('#totaldays').val(days);
}
这很有效。现在的问题是下一个AJAX请求函数showDays()
停止工作。我在success
内尝试了这个,因为其他答案在这里建议,但它仍然不起作用。
$("#datepicker3").datepicker({
onSelect: showDays
});
AJAX电话:
$(document).ready(function() {
///PARA SELECCIONAR NUMERO DE HABITACION
$('#id_residencial').on('change', function() {
var id_residencial = $(this).val();
if (id_residencial) {
$.ajax({
type: 'POST',
url: 'get_id_habitacion.php',
data: 'id_residencial='+id_residencial,
success: function(html) {
$('#id_habitacion').html(html);
}
});
}
});
});
解决方案:
我放$('.datepicker3').not('.hasDatePicker').datepicker();
$(document).ready(function() {
///PARA SELECCIONAR NUMERO DE HABITACION
$('#id_residencial').on('change', function() {
var id_residencial = $(this).val();
if (id_residencial) {
$.ajax({
type: 'POST',
url: 'get_id_habitacion.php',
data: 'id_residencial='+id_residencial,
success: function(html) {
$('#id_habitacion').html(html);
$('.datepicker3').not('.hasDatePicker').datepicker();
}
});
}
});
});
它的工作:)