Thursday, March 1, 2018

How to disable dates in jQuery DatePicker

<link rel="stylesheet" href="http://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>
  /* create an array of days which need to be disabled */
var array = ["2016-12-14","2016-12-15","2016-12-16","2017-02-16"];

$(function() {
    $("#datepicker").datepicker({
        beforeShowDay: function(date){
        var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
        return [ array.indexOf(string) == -1 ]
    }
    });

});

  </script>
<body>
Date: <div id="datepicker"></div>
</body>

No comments:

Post a Comment