简体   繁体   English

如何从Jquery UI Datepicker禁用特定日期

[英]How to disable the specific date from Jquery UI datepicker

I want to disable the dates 20,21,25 OCT 2015. I am using the JQuery UI datepicker but i cannot getting output. 我想禁用2015年10月20日21日的日期。我正在使用JQuery UI datepicker,但无法获取输出。 Here is my sample code.It will help you. 这是我的示例代码,它将为您提供帮助。

<!doctype html>
<html lang="en">
   <head>
      <meta charset="utf-8">
      <title>jQuery UI Datepicker functionality</title>
      <link href="http://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel="stylesheet">
      <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
      <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

      <!-- Javascript -->
      <script>
        var unavailableDates = ["10/20/2015", "10/21/2015", "10/25/2015"]; 

            function unavailable(date) {
                dmy = date.getDate() + "-" + (date.getMonth() + 1) + "-" + date.getFullYear();
                if ($.inArray(dmy, unavailableDates) == -1) {
                    return [true, ""];
                } else {
                    return [false, "", "Unavailable"];
                }
            }

            $(function() {
                $("#iDate").datepicker({
                    dateFormat: 'dd MM yy',
                    beforeShowDay: unavailable
                });

            });
      </script>
   </head>
   <body>
      <!-- HTML --> 
      <p>Enter Date: <input type="text" id="datepicker-5"></p>
   </body>
</html>

you can try this 你可以试试这个

d = $("#myDatepicker1").datepicker("getDate");
$("#myDatepicker2").datepicker("setDate", new Date(d.getFullYear()+1,d.getMonth(),d.getDate()));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM