简体   繁体   中英

JQuery Datepicker error after Postback with Ajax

my Datepicker works fine, but after postback it doesn't work any more. I tried also pageLoad method but it still doesn't work.

I have a List of Items from database. If I click an item of the list, I get the information about it in a table from database (I used POST Method with Ajax).

Jquery:

<script>
$(function() {
      var pickerOpts = { dateFormat: $.datepicker.ATOM }; 
      $("#datepicker").datepicker(pickerOpts);
             });
</script>

Textfield:

echo("<input type='text' id='datepicker' value='$db[deadline]'>");

I've googled for hours but found nothing that worked for me.

EDIT NOTE: Errors after trying Rahil Wazir's help:

在此处输入图片说明

Use this:

<script>
$(function() {
    var pickerOpts = { dateFormat: $.datepicker.ATOM }; //Place this inside below .on handler if this also updates.
    $(document).on('focus', '#datepicker', function(e){
        $(this).datepicker(pickerOpts);
    });
});
</script>

You have to use $(document).on handler when dom updates. And add event focus to trigger the datepicker handler.

Edited:
See this answer for further help

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