<script>
$(function() {
$.datepicker.setDefaults({dateFormat: 'yy-mm-dd'});
$("#datepicker1").datepicker({ beforeShowDay: $.datepicker.noWeekends });
$( "#datepicker1" ).datepicker({ minDate: 0});
$( "#datepicker1" ).datepicker();
});
</script>
我有上面的代码,我想从我的JQuery datepicker中禁用周末和以前的日期..但它的作用是它只会禁用周末而不是过去几天。我哪里出错???
答案 0 :(得分:1)
您可以尝试这样
$(function() {
var date = new Date();
var currentMonth = date.getMonth();
var currentDate = date.getDate();
var currentYear = date.getFullYear();
$('#txtDate').datepicker({
minDate: new Date(currentYear, currentMonth, currentDate), // will disable past days
beforeShowDay: $.datepicker.noWeekends // Will disable weekends
});
});
文档
答案 1 :(得分:1)
将所有设置传递给一个电话
$(function () {
$.datepicker.setDefaults({
dateFormat: 'yy-mm-dd'
});
$("#datepicker1").datepicker({
beforeShowDay: $.datepicker.noWeekends,
minDate: 0
});
});
答案 2 :(得分:1)
<强>小提琴:强>
<强> http://jsfiddle.net/rLnTQ/877/ 强>
您可以一次性使用所有选项,而不是单独执行。 你多次调用datepicker,这是不需要的。
$(function() {
$.datepicker.setDefaults({
// here we can have all the common properties which we need for all the datepickers
dateFormat: 'yy-mm-dd',
duration:"slow"
});
$('#datepicker1').datepicker({
minDate:0,
dateFormat: 'yy-mm-dd', // this is for single datepicker.
beforeShowDay: $.datepicker.noWeekends
});
});
答案 3 :(得分:0)
每次指定一个选项时,你都会重新初始化datepicker,以实现这两个要求,这样做
JQUERY CODE:
$("#datepicker1").datepicker({
minDate: 0,
beforeShowDay: $.datepicker.noWeekends
});
现场演示: http://jsfiddle.net/dreamweiver/XsG27/3/
快乐编码:)