简体   繁体   中英

JQuery Datepicker set input[type=“text”]

Ok i have a <input id="has-assigned-date"> , I want to set or put the default value. The value from the db when fetched it should be on the input box this will occur on page ready. Sorry for the poor english...

Here's my code:

$("#has-assigned-date").datepicker({ 
   minDate: -20, 
   maxDate: "+12M +10D" , 
   dateFormat: "yy-mm-dd",      
   defaultDate: dd, 
   setDate: (def[2] - 1) + "/" + def[1] + "/" + def[0]});

Please use the keyword 'option', and set the date as a new Date object.

$("#has-assigned-date").datepicker('option', { 
   minDate: -20, 
   maxDate: "+12M +10D" , 
   dateFormat: "yy-mm-dd",      
   defaultDate: dd, 
   setDate: new Date((def[2] - 1) + "/" + def[1] + "/" + def[0])
   });

setDate needs to be called separately; it's not an option.

It also needs to be in the same format as the dateFormat ("yy-mm-dd"), or a Date object.

$("#has-assigned-date").datepicker({ 
   minDate: -20, 
   maxDate: "+12M +10D" , 
   dateFormat: "yy-mm-dd",      
   defaultDate: dd, 
}).datepicker('setDate', new Date((def[2] - 1) + "/" + def[1] + "/" + def[0]));

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