I would like to set today's date as a maxdate for jQuery datepicker in order to prevent users from picking date greater than today's date
我想将今天的日期设置为jQuery datepicker的maxdate,以防止用户选择超过今天的日期的日期
4 个解决方案
#1
120
$(".datepicker").datepicker({maxDate: '0'});
This will set the maxDate to +0 days from the current date (i.e. today). See:
这会将maxDate从当前日期(即今天)设置为+0天。看到的:
http://api.jqueryui.com/datepicker/#option-maxDate
http://api.jqueryui.com/datepicker/ option-maxDate
#2
11
http://api.jqueryui.com/datepicker/#option-maxDate
http://api.jqueryui.com/datepicker/ option-maxDate
$( ".selector" ).datepicker( "option", "maxDate", '+0m +0w' );
#3
4
If you're using bootstrap 3 date time picker, try this:
如果您正在使用bootstrap 3日期时间选择器,请尝试以下操作:
$('.selector').datetimepicker({ maxDate: $.now() });
#4
1
For those who dont want to use datepicker method
对于那些不想使用datepicker方法的人。
var alldatepicker= $("[class$=hasDatepicker]");
alldatepicker.each(function(){
var value=$(this).val();
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();
if(dd<10) {
dd='0'+dd
}
if(mm<10) {
mm='0'+mm
}
today = mm+'/'+dd+'/'+yyyy;
if(value!=''){
if(value>today){
alert("Date cannot be greater than current date");
}
}
});
#1
120
$(".datepicker").datepicker({maxDate: '0'});
This will set the maxDate to +0 days from the current date (i.e. today). See:
这会将maxDate从当前日期(即今天)设置为+0天。看到的:
http://api.jqueryui.com/datepicker/#option-maxDate
http://api.jqueryui.com/datepicker/ option-maxDate
#2
11
http://api.jqueryui.com/datepicker/#option-maxDate
http://api.jqueryui.com/datepicker/ option-maxDate
$( ".selector" ).datepicker( "option", "maxDate", '+0m +0w' );
#3
4
If you're using bootstrap 3 date time picker, try this:
如果您正在使用bootstrap 3日期时间选择器,请尝试以下操作:
$('.selector').datetimepicker({ maxDate: $.now() });
#4
1
For those who dont want to use datepicker method
对于那些不想使用datepicker方法的人。
var alldatepicker= $("[class$=hasDatepicker]");
alldatepicker.each(function(){
var value=$(this).val();
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();
if(dd<10) {
dd='0'+dd
}
if(mm<10) {
mm='0'+mm
}
today = mm+'/'+dd+'/'+yyyy;
if(value!=''){
if(value>today){
alert("Date cannot be greater than current date");
}
}
});