beforeShowDay Datepicker

时间:2011-05-02 12:01:12

标签: jquery jquery-ui datepicker

我需要调用两个函数或弄清楚如何合并与Jquery UI Datepicker交互的两个函数。一个突出显示某个日期,另一个禁用日期。如果我只调用一个函数,我可以正常工作。我需要有关如何合并它们的帮助。

        <script type="text/javascript">
        //<![CDATA[


        /* create an array of days which need to be disabled */
        var disabledDays = ["2011-5-21","2011-5-22"];

        var overrideDays = ["2011-5-15","2011-5-16"];


          function getAvailableDays(date){
            var dateAsString = date.getFullYear().toString() + "-" + (date.getMonth()+1).toString() + "-" + date.getDate();
            var result = jQuery.inArray( dateAsString, disabledDays ) ==-1 ? [true] : [false];

            return result
          }

          function setOverrideDays(date){
            var dateAsString = date.getFullYear().toString() + "-" + (date.getMonth()+1).toString() + "-" + date.getDate();
            var result = jQuery.inArray( dateAsString, overrideDays ) == -1 ? [true] : [true,"test2"];
                return result
          }
        //]]>
        </script>


        <script type="text/javascript">
        jQuery(document).ready(function($){
            $("#datepicker").datepicker({
                    dateFormat:'mm/dd/yy',
                    beforeShowDay: getAvailableDays,

                    minDate: 0
            });


        });</script>

1 个答案:

答案 0 :(得分:0)

也许这个:

function setDays(date) {
    var dateAsString = date.getFullYear().toString() + "-" + (date.getMonth() + 1).toString() + "-" + date.getDate();
    if(jQuery.inArray(dateAsString, overrideDays) != -1){
        return [true, "test2"];
    } 
    if(jQuery.inArray(dateAsString, disabledDays) != -1){
        return [false];
    }
    return [true];
}

<强> Example on jsfiddle