0

我有一个问题,我试图datepicker在不同的 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 函数是相同的,因为使用此代码datepicker1是正常的但datepicker2不起作用。

当我评论它的 beforeShowDay 时,datepicker2它可以工作,但不会阻塞日子。

问候!

4

0 回答 0