jQuery - cannot bind events to dynamic elements?

后端 未结 6 566
借酒劲吻你
借酒劲吻你 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:27

    Two things come to my mind:

    1. The link has no text so you are not clicking it.
    2. You aren't even appending it to the dom.

    Here there is a fiddle that works with code very similar to yours.

    var a = $('ASD');
    
    a.click(function() {
        alert('a');
    });
    
    a.appendTo($("body"));
    

提交回复
热议问题