如何在不影响其他值的情况下使jquery ui中的日期选择器禁用sunday

How to make datepicker in jquery-ui disable sunday without affecting other values

本文关键字:ui 日期 选择器 sunday jquery 情况下 影响 其他      更新时间:2023-09-26

我想制作一个不包括周日的日期选择器。但是,在我的工作中,我不知道为什么它不起作用。任何形式的帮助都将不胜感激。

非常感谢。

这是我的代码

<table>
    <tr>
        <td><label > Schedule Day : </label></td>
        <td><input type="text" id='date' name="date" required></td>
        <script src="../../Script/jQuery/jquery-ui/js/jquery-ui.js"></script>
        <link rel="stylesheet" href="../../Script/jQuery/jquery-ui/css/ui-lightness/jquery-ui-1.9.2.custom.css" />
        <script>

        $("#date").datepicker({

            minDate: 0,
            maxDate: 7,
            changeMonth:true,
            changeYear:false,
            dateFormat:"yy-mm-dd",
            inline: true,
            beforeShowDay: noSunday;
        });
        function noSunday(date){ 
            return [date.getDay() != 0, ''];
        }; 

        </script>   
        <td><input type='submit' id='btn' name="btnchkavlb" value="Check Availability"></td>
    </tr>
</table>

您必须使用DatePicker的beforeShowDate事件,如下所示:

$(""#date"").datepicker({
        minDate: 0,
        maxDate: 7,
        changeMonth:true,
        changeYear:false,
        dateFormat:"yy-mm-dd",
        inline: true,
beforeShowDay: function(date) {
var day = date.getDay();
return [day != 0,''];
}
})​​​​​;​

您可以使用

function noSunday(date){
    var d = date.getDay();
    return [(d > 0), ''];
}; 

试试这个:

function noSunday(date){
    var day = date.getDay();
    return [(day > 0), ''];
}; 

并将jquery代码放入document.ready()块中。

对不起,我已经回答了我自己的问题x_x

我试着把之前的放映日:noSunday放在最上面,结果成功了。

$("#date").datepicker({                                     
    beforeShowDay: noSunday,
    minDate: 0,
    maxDate: <?php echo $maxDaysBeforeSched;?>,
    changeMonth:true,
    changeYear:false,
    dateFormat:"yy-mm-dd",
    inline: true
});