Jquery Datepicker 日期禁用

Jquery Datepicker 日期禁用

如上图所示:禁用3月份的1号以及5号 这里目前还有一个问题 初始化的时候 默认是禁止的日期 因为当前日期是 当选择了别的日期后 3月1号就不能在选回来了
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- <link href="jquery-ui-1.13.1.custom/jquery-ui.css" rel="stylesheet" type="text/css"/> -->
    <link href="js/jquery-ui.min.css" rel="stylesheet" type="text/css" />
    <style>
        .specialdays {
            background: #E17009 !important;
            opacity: 0.8 !important;
            /*添加半透明效果*/
            -moz-border-radius: 3px !important;
            -webkit-border-radius: 3px !important;
            border-radius: 7px !important;
            color: red !important;
        }
    </style>
</head>

<body>
    <h2 class="demoHeaders">Datepicker</h2>
    <input type="text" id="alternate" size="30">
    <div id="datepicker"></div>
</body>
<script src="js/jquery.js"></script>
<script src="js/jquery-ui.min.js"></script>
<script>
    natDays = ['2022-02-28', '2022-03-01', '2022-03-05'];
    $("#datepicker").datepicker({
        altField: "#alternate",
        dateFormat: "yy-mm-dd",
        monthNames: ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"],
        dayNamesMin: ['日', "一", "二", "三", "四", "五", "六"],
        prevText: "上一月",
        nextText: "下一月",
        showOtherMonths: true,
        selectOtherMonths: true,
        minDate: -1, 
        maxDate: "+3M",
        defaultDate:null,
        beforeShowDay: RestDaySet
    });
    function Appendzero(obj) {
        if (obj < 10) return "0" + obj; else return obj;
    }
    function RestDaySet(date) {
        for (var i = 0; i < natDays.length; i++) {
            var curr_date = Appendzero(date.getDate());
            var curr_month = Appendzero(date.getMonth() + 1);
            var curr_year = date.getFullYear();
            var formatDate = curr_year + "-" + curr_month + "-" + curr_date;
            if ($.inArray(formatDate, natDays) != -1) {
                return [false];
            } else {
                return [true]
            }
        }

    }
</script>

</html>

 

demo 地址链接: https://pan.baidu.com/s/1f7sRVu7r-6th1T9RFAWClg?pwd=i5u3 提取码: i5u3 

 

上一篇:油猴-知乎自动关闭登录弹窗,自动跳转链接


下一篇:istio kiali jaeger 关联