jquery datepicker range (mindate maxdate) is not w

2019-02-25 03:57发布

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.

  <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>

6条回答
冷血范
2楼-- · 2019-02-25 04:10

You can also test this.

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

$('#datepicker1').on('change', function() {
  $('#datepicker2').datepicker({
    startDate: $('#datepicker1').val()
  })
});
查看更多
爷、活的狠高调
3楼-- · 2019-02-25 04:13
$('#datepicker').datepicker({
            maxDate: '0'}),

Use '0' for select max date today

You can also reference jQueryUI Api

查看更多
别忘想泡老子
4楼-- · 2019-02-25 04:31

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".

查看更多
爷的心禁止访问
5楼-- · 2019-02-25 04:31

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'.

查看更多
▲ chillily
6楼-- · 2019-02-25 04:32

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

and in html min-date="today"

查看更多
Evening l夕情丶
7楼-- · 2019-02-25 04:34
$('#datepicker').datepicker({
                maxDate: '+1m',
                minDate: '-20d',
                });

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

查看更多
登录 后发表回答