minDate beforeShowDay
<script>
$(function() {
$.datepicker.setDefaults({dateFormat: 'yy-mm-dd'});
$("#datepicker1").datepicker({ beforeShowDay: $.datepicker.noWeekends });
$( "#datepicker1" ).datepicker({ minDate: 0});
$( "#datepicker1" ).datepicker();
});
</script>
我有上面的代码,我想禁用周末和以前的日期从我的JQuery日期拾取器。但它所做的是,它只禁用周末,而不是过去的日子。我哪里做错了?
将所有设置传递给单个调用
$(function () {
$.datepicker.setDefaults({
dateFormat: 'yy-mm-dd'
});
$("#datepicker1").datepicker({
beforeShowDay: $.datepicker.noWeekends,
minDate: 0
});
});
你可以这样试试
$(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
});
});
<<h2> 小提琴演示/strong> 文档
小提琴:
http://jsfiddle.net/rLnTQ/877/
你可以在一个镜头中使用所有的选项,而不是单独做。您多次调用日期选择器,这是不必要的。
$(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
});
});
每次为它指定一个选项时,您都在重新初始化日期选择器,为了实现两个要求,请这样做
JQUERY代码: $("#datepicker1").datepicker({
minDate: 0,
beforeShowDay: $.datepicker.noWeekends
});
现场演示:http://jsfiddle.net/dreamweiver/XsG27/3/
快乐编码:)