我遇到的问题是我试图在不同的html页面上有2个日期选择器。
我的js代码是:
//Datepicker
function closedDays(date) {
var cloDays = "[";
var available_days = $('#booking_available_days').val();
for(var i=0;i<=available_days.length;i++){
if(available_days[i]=="1"){
var day = (i+1) % available_days.length;
cloDays +="'"+ day +"'";
if(i == available_days.length) cloDays +=",";
}
}
var sDate = date.getDay().toString();
var fecha_actual = new Date();
var string = "Fecha Actual:"+fecha_actual.getDate()+"/"+fecha_actual.getMonth()+"/"+fecha_actual.getFullYear();
string += " TimeStamp:"+fecha_actual.getTime();
string += " Fecha Actual Calendario:" + date.getDate()+"/"+date.getMonth()+"/"+date.getFullYear();
string += " TimeStamp:"+date.getTime();
if($.inArray(sDate, cloDays) != -1 && fecha_actual.getDate() == date.getDate() && fecha_actual.getMonth() == date.getMonth() && fecha_actual.getFullYear() == date.getFullYear())
return [true, "green_background","Disponible"];
if ($.inArray(sDate, cloDays) != -1 && (fecha_actual.getTime() < date.getTime()))
return [true, "green_background","Disponible"];
else
return [false,"","No Disponible"];
}
$(function () {
$.datepicker.regional['es'] = {
closeText: 'Cerrar',
prevText: '<Ant',
nextText: 'Sig>',
currentText: 'Hoy',
monthNames: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio',
'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'],
monthNamesShort: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun',
'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'],
dayNames: ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'],
dayNamesShort: ['Dom', 'Lun', 'Mar', 'Mié;', 'Juv', 'Vie', 'Sáb'],
dayNamesMin: ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sá'],
weekHeader: 'Sm',
dateFormat: 'yy-mm-dd',
firstDay: 1,
isRTL: false,
showMonthAfterYear: false,
yearSuffix: ''
};
$.datepicker.setDefaults($.datepicker.regional["es"]);
$("#datepicker1").datepicker({
firstDay: 1,
minDate: "0D",
beforeShowDay: closedDays
});
$("#datepicker2").datepicker({
firstDay: 1,
minDate: "0D",
beforeShowDay: closedDays
});
});
我的输入字段就是这样:
<input type='text' id='datepicker2' name='excursion_date'/>
开发人员控制台抛弃了我:
Uncaught TypeError: Cannot read property 'length' of undefined functions.js:213
closedDays functions.js:213
$.extend._generateHTML jquery-ui.js:9321
$.extend._updateDatepicker jquery-ui.js:8367
$.extend._showDatepicker jquery-ui.js:8335
x.event.dispatch jquery.js:5
v.handle jquery.js:5
问题是beforeShowDay函数是相同的,因为使用此代码时,datepicker 1是正常的但是datepicker2不起作用。
当我评论datepicker2的beforeShowDay时,它可以正常工作,但不会阻止这些日子。
问候!