可以使用 beforeShowDay 這個預設的 event 來做取消週末或週日的日期格子的動作。
範例:如果想要取消所有週末的日期格子使之不能選取,可以使用 Datepicker 內建的 noWeekends 函式。
$(document).ready(function() { $(function() { $('#datepicker_reserve').datepicker({ beforeShowDay: noWeekends }); }); });
範例:如果想要取消所有週日的日期格子使之不能選取,我們可以將 Datepicker 內建的 noWeekends 函式稍做修改即可。
getDay(): 0= 週日; 6= 週六
$(document).ready(function() { $(function() { $('#datepicker_reserve').datepicker({ beforeShowDay: noSundays }); }); }); function noSundays(a) { a=a.getDay(); return[a>0&&a<7,""]; }
參考資訊:
- http://talk.ernestchiang.com/2010/06/jquery-ui-datepicker.html
- http://yhhuang1966.blogspot.tw/2013/04/jquery-ui-datepicker.html
- http://jimgifw.blogspot.tw/2011/05/jquery-ui-datepicker-1812_10.html