jquery datepicker 范围(mindate maxdate)不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11899472/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 11:03:06  来源:igfitidea点击:

jquery datepicker range (mindate maxdate) is not working

jquerydatepickerrangemaxdatemindate

提问by silvster27

I'm trying to set a range for a jquery datepicker that I have on my form but when I open the form it allows me to select any date.

我正在尝试为表单上的 jquery 日期选择器设置一个范围,但是当我打开表单时,它允许我选择任何日期。

  <input class="span2 datepicker" name="tw#local#changeRequest#DeliveryDate" type="text" id="dp1">


 <!-- jQuery -->
 <script type="text/javascript" src="<#=tw.system.model.findManagedFileByPath('jquery-1.7.2.min.js', TWManagedFile.Types.Web).url;#>"></script>

 <!-- Datepicker Script -->
 <script type="text/javascript" src="<#=tw.system.model.findManagedFileByPath('bootstrap-datepicker_new.js', TWManagedFile.Types.Web).url;#>"></script>

 <script type="text/javascript">
 $(document).ready(function(){

 $( "#datepicker" ).datepicker({ minDate: -20, maxDate: "+1M +10D" });

 });
 </script>

回答by Lyubomir Vasilev

As far as I know, it should be done like this:

据我所知,应该这样做:

$("#datepicker").datepicker('option', {minDate: <some date>, maxDate: <some date>});

What you are missing is that you should set them using 'option'.

您缺少的是您应该使用“选项”设置它们。

回答by VishalDream

$('#datepicker').datepicker({
            maxDate: '0'}),

Use '0'for select max date today

'0'今天的选择最多的日期

You can also reference jQueryUI Api

你也可以参考jQueryUI Api

回答by vadim

$('#datepicker').datepicker({
                maxDate: '+1m',
                minDate: '-20d',
                });

When min and max date are expressions they should be as strings and properly defined. Hereis link for jquery ui datepicker MaxDate section.

当 min 和 max date 是表达式时,它们应该是字符串并正确定义。是 jquery ui datepicker MaxDate 部分的链接。

回答by VivekS

One more thing, you might have noticed that already, but your selector is searching for ID as "datepicker". Whereas, your datepicker is your CLASS. So I think you need to change from "#datepicker" to ".datepicker".

还有一件事,您可能已经注意到了,但是您的选择器正在将 ID 搜索为“datepicker”。而您的日期选择器就是您的 CLASS。所以我认为您需要从“#datepicker”更改为“.datepicker”。

回答by yogesh mhetre

just add in controller if you are using angularjs $scope.today = new Date()

如果您使用的是 angularjs $scope.today = new Date(),只需添加控制器

and in html min-date="today"

并在 html min-date="today"

回答by AlejandroBec

You can also test this.

您也可以对此进行测试。

$('#datepicker1').datepicker({
  format: 'mm/dd/yyyy',
});

$('#datepicker1').on('change', function() {
  $('#datepicker2').datepicker({
    startDate: $('#datepicker1').val()
  })
});