I have a function that imports information into a form. I am using jQuery to place a date into an input box. The ID of the input box is "depart_date" and I am trying to insert the value of (let's say) 04/01/2012.
$('input#depart_date').replaceWith('<input class="input_med hasDatepicker" type="text" id="depart_date" name="depart_date" value="04/01/2012">');
This works just fine. However, I lose my datepicker. I have even tried to "reinitialize" it by using
$( "#depart_date" ).datepicker({ minDate: 0});
I just don't understand how to get my datepicker back.
You're not just changing the value, you're replacing the object entirely (and removing all the UI hooks [click, focus, blur events] along with it).
Try using just $('#depart_date').val('04/01/2012');
to assign the value. Or, better yet $('#datepart').datepicker('setDate', '04/01/2012');
Why replace the input
? Why not simply change the value?
$('input#depart_date').val("04/01/2012");
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.