开发者

jQuery UI Datepicker be made to disable weekends and holidays?

I have seen an exact question being answered, but the problem is, I have absolutely no idea where to paste the codes shown here for 开发者_如何学Cmine to work. I am really a noob when it comes to programming.

Would appreciate if someone would be so kind to enlighten me as I desperately need to get my calendar working. :(

Thank you so much.


var holidays= ["2014-7-30","2015-07-29","2013-03-16"]

$('input').datepicker({
beforeShowDay:  function(date){
    var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
     var noWeekend = $.datepicker.noWeekends(date);
         if (noWeekend[0]) {
        return  [$.inArray(string, holidays) == -1];
        }
        else
        return noWeekend;
    }
});


I'll try to answer:

How to start you'll find - here

You will need theese: (link them in top of your page.)

  1. jQuery Library: Datepicker requires including jQuery.
  2. JavaScript: ui.core.js and ui.datepicker.js
  3. CSS Theme: Create your theme with ThemeRoller

You can find great demo about basis - here

<script>
 $(function() {
   /*function that makes appear datepicker + you add option to disable Weekends*/
   $(".selector").datepicker({ beforeShowDay: $.datepicker.noWeekends }) 
 });
</script>

<div id="demo">
  <p>Date: <input class="selector" type="text"></p> //input field that calls the function
</div>

2 things to do:

  1. link jquery.js + ui.core.js and ui.datepicker.js + your css theme to your page
  2. paste this code into your webpage.

I can suggest you to do as i did - run threw a lot of tutorials, and most important thing to do - experiment!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜