在jQuery datepicker中更改不同表单的可选日期,同时保持其他选项不变
我所要做的就是保持日期选择器的代码保持干燥,但我似乎无法使我的更改生效。我想在所有日期选择器中保留一组常规选项:在jQuery datepicker中更改不同表单的可选日期,同时保持其他选项不变,jquery,datepicker,jquery-ui-datepicker,Jquery,Datepicker,Jquery Ui Datepicker,我所要做的就是保持日期选择器的代码保持干燥,但我似乎无法使我的更改生效。我想在所有日期选择器中保留一组常规选项: var dateToday = new Date(); $(".selectdate").datepicker({ dateFormat: 'd MM yy', showOtherMonths: true, selectOtherMonths: true }); 但是有一些日期选择器我需要maxDate选项,还有一些我需要minDate选项,但我无法让它工
var dateToday = new Date();
$(".selectdate").datepicker({
dateFormat: 'd MM yy',
showOtherMonths: true,
selectOtherMonths: true
});
但是有一些日期选择器我需要maxDate选项,还有一些我需要minDate选项,但我无法让它工作。例如:
$("#calldate").datepicker({
maxDate: dateToday
});
因此,我有一个id为“calldate”和类为“selectdate”的输入字段,我本以为这会起作用,但事实并非如此-日历显示时所有选项都设置为$(“.selectdate”)。。。。但是maxDate不起作用。我不想为我所有的日期选择器重复代码,比如:
$("#fromdate").datepicker({
dateFormat: 'd MM yy',
showOtherMonths: true,
selectOtherMonths: true,
minDate: dateToday
});
$("#calldate").datepicker({
dateFormat: 'd MM yy',
showOtherMonths: true,
selectOtherMonths: true,
maxDate: dateToday
});
我希望这是有意义的,有人可以帮我排序,谢谢您可以使用
$.datepicker.setDefaults()
然后在您希望应用更多/不同选项的元素上调用.datepicker()
时覆盖/添加新选项,如下所示:
$.datepicker.setDefaults({
日期格式:“d MM yy”,
showOtherMonths:是的,
选择OtherMonths:true
});
$('#fromdate')。日期选择器();
$('#calldate').datepicker({minDate:0})代码>
#调用日期
#起始日期
谢谢,这正是我所需要的,也是我的梦想:)