jQuery datepicker won't work on a AJAX added html element

前端 未结 6 1399
小鲜肉
小鲜肉 2020-12-05 12:06

I have a jQuery datepicker function bound to the \"birthday\" input html element, written in the page header:



        
6条回答
  •  广开言路
    2020-12-05 12:43

    You need to use .live() so that any newly added elements have the event handler attached: http://api.jquery.com/live/

    $('#birthday').bind('load', function() {
        $(this).datepicker();
    });
    

    EDIT

    .live() documentation states, that it is a bit out of date. With new versions of jquery (1.7+) use .on().

提交回复
热议问题