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.)
- jQuery Library: Datepicker requires including jQuery.
- JavaScript: ui.core.js and ui.datepicker.js
- 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:
- link jquery.js + ui.core.js and ui.datepicker.js + your css theme to your page
- 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!
精彩评论