jQuery - cannot bind events to dynamic elements?

后端 未结 6 608
借酒劲吻你
借酒劲吻你 2021-01-13 07:58

I\'ve come to maintain a piece of javascript that downloads some JSON data from the server, builds a new table row (like $(\') and inserts i

6条回答
  •  粉色の甜心
    2021-01-13 08:07

    You can use event delegation like so.

    $('body').on('click','.foo',function(){
        alert('foo');
    });
    

    This will allow you to set the event handler before the element is present.

提交回复
热议问题