jQuery event handler .on() not working

前端 未结 6 1230
小鲜肉
小鲜肉 2020-12-08 09:49

I want to attach a event to dynamically created element class.So i used live function but it was not triggered. So checked live function reference ,there i red below notes

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-08 10:34

    From the documentation of .live():

    Rewriting the .live() method in terms of its successors is straightforward; these are templates for equivalent calls for all three event attachment methods:

    $(selector).live(events, data, handler);                // jQuery 1.3+
    $(document).delegate(selector, events, data, handler);  // jQuery 1.4.3+ 
    $(document).on(events, selector, data, handler);        // jQuery 1.7+
    

    So in your case, you would do:

    $(document).on('click', '.date_picker_disabled', function(event){
        alert('hi');
    });
    

提交回复
热议问题