datepicker - 错误daySettings未定义

时间:2013-03-12 15:21:42

标签: jquery jquery-ui datepicker undefined jquery-ui-datepicker

我正在尝试禁用jquery ui的datepicker函数的某些天, 但此代码返回错误:daySettings is undefinedhttp://code.jquery.com/ui/1.9.2/jquery-ui.js。看来是对的,我不知道...... 请帮忙!

         var $j = jQuery.noConflict(); 
     $j(document).ready(function() {
        var group_id = <? echo $bp->groups->current_group->id; ?>;
        var userid = <? echo $bp->loggedin_user->id; ?>;
        var myBadDates = new Array ();
    function checkAvailability(mydate){
    jQuery.post(  
        ajaxurl,
        {   
        action : 'check_date',
        verificadata: "true", userid: userid, group_id: group_id
        },
        function( response ) {
        obj = JSON.parse(response);
        var key, quanti = 0; 
            for(key in obj.prenotati) { 
                if(obj.prenotati.hasOwnProperty(key)) { 
                    var datafrom = obj.prenotati[quanti].datafrom;
                    var datato = obj.prenotati[quanti].datato;
                    myBadDates.push(datafrom);
                    myBadDates.push(datato);
                    quanti++;
                }
            }
            var ritorno = true;
            var returnclass ="available";
            checkdate = $j.datepicker.formatDate('yy-mm-dd', mydate);
                for(var i = 0; i < myBadDates.length; i++) { 
                    $j(myBadDates[i])
                        if(myBadDates[i] == checkdate) { 
                        ritorno = false; returnclass="unavailable"; 
                        } 
                }
                return [ritorno,returnclass]; 
        }
    )
}       

/* $myBadDates = new array("2013-03-03","2013-03-05");      
function checkAvailability(mydate){
        var $return=true;
        var $returnclass ="available";
        $checkdate = $j.datepicker.formatDate('yy-mm-dd', mydate);
        for(var i = 0; i < $myBadDates.length; i++) { 
            if($myBadDates[i] == $checkdate) { 
                $return = false; $returnclass= "unavailable"; 
            } 
        } 
        return [$return,$returnclass]; 
        } */
            $j('#datafrom').datepicker({
             dateFormat : 'yy-mm-dd',
             beforeShowDay: checkAvailability,
             onSelect: function(dateText, inst) {
                $j("#datafrom").val(dateText);
            }
        });
        $j('#datato').datepicker({
             dateFormat : 'yy-mm-dd',
             beforeShowDay: checkAvailability,
                onSelect: function(dateText, inst) {
                    $j("#datato").val(dateText);
                }
        }); 
 });

1 个答案:

答案 0 :(得分:0)

您的问题与范围相关,您尝试return成功方法post结果,但实际上并非您的功能返回

我在下面所做的只是将返回变量的声明移到函数范围的顶部,然后我在函数范围的顶部添加了return语句

var $j = jQuery.noConflict(); 
     $j(document).ready(function() {
        var group_id = <? echo $bp->groups->current_group->id; ?>;
        var userid = <? echo $bp->loggedin_user->id; ?>;
        var $myBadDates = new Array ();
    jQuery.post(  
        ajaxurl,
        {   
        action : 'check_date',
        verificadata: "true", userid: userid, group_id: group_id
        },
        function( response ) {
        obj = JSON.parse(response);
        var key, count = 0; 
            for(key in obj.prenotati) { 
                if(obj.prenotati.hasOwnProperty(key)) { 
                    var datafrom = obj.prenotati[count].datafrom;
                    var datato = obj.prenotati[count].datato;
                    $myBadDates.push(datafrom); 
                    $myBadDates.push(datato);
                    count++;
                }
            }
            $j($myBadDates).appendTo("#item-meta");
        }
    )     
        function checkAvailability(mydate){
        var $return=true;
        var $returnclass ="available";
            checkdate = $j.datepicker.formatDate('yy-mm-dd', mydate);
                for(var i = 0; i < $myBadDates.length; i++) { 
                        if($myBadDates[i] == checkdate) { 
                    //  alert($myBadDates[i]);
                        $return = false; $returnclass= "unavailable"; 
                        } 
                }
        return [$return,$returnclass];  
        }