jQuery 如何将日期选择器的最大日期限制为今天?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8010448/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to limit datepicker's max date to today?
提问by Dragan
The questions is in the Title. I have two datepickers, from and to. I want to limit the from datepicker to the current date. How do I do that? Thanks in advance!
问题在标题中。我有两个日期选择器,from 和 to。我想将 from datepicker 限制为当前日期。我怎么做?提前致谢!
采纳答案by Guillaume Cisco
Use the maxDate options : http://jqueryui.com/demos/datepicker/#option-maxDate
使用 maxDate 选项:http: //jqueryui.com/demos/datepicker/#option-maxDate
Set a maximum selectable date via a Date object or as a string in the current dateFormat, or a number of days from today (e.g. +7) or a string of values and periods ('y' for years, 'm' for months, 'w' for weeks, 'd' for days, e.g. '+1m +1w'), or null for no limit.
通过 Date 对象或当前 dateFormat 中的字符串设置最大可选日期,或从今天开始的天数(例如 +7)或一串值和句点('y' 表示年,'m' 表示月, 'w' 表示周,'d' 表示天,例如 '+1m +1w'),或 null 表示没有限制。
For example : $( ".selector" ).datepicker( "option", "maxDate", new Date() );
例如 : $( ".selector" ).datepicker( "option", "maxDate", new Date() );