简体   繁体   中英

jQuery date picker year 1927 format dd mm y issue

jQuery DatePicker for format dd mm y breaking

I type in 01 01 27 it breaks it doesn't shows the date selected in calendar

Is it a jQuery bug ?

It accepts all values above year 1927

HTML

<p>Date: <input type="text" id="datepicker"></p>

JS

  $( "#datepicker" ).datepicker({
    dateFormat: "dd mm y",
    changeMonth: true,
    changeYear: true,
    minDate: "-100Y",
    maxDate: "-18Y"
});

 $(function () { $( "#datepicker" ).datepicker({ dateFormat: "dd mm y", changeMonth: true, changeYear: true, minDate: "-100Y", maxDate: "-18Y" }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <p>Date: <input type="text" id="datepicker"></p> 

looks like yearRange is something you can use:

 $(function() { $("#datepicker").datepicker({ dateFormat: "dd mm y", changeMonth: true, changeYear: true, yearRange: "c-100:c-18" }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <p>Date: <input type="text" id="datepicker"></p> 

I have figured out the answer

adding shortYearCutoff: "1", solves my problem

For more details check here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM