0

I have several <div class="some_class"> . I bind to it an event to it through

$('.some_class').on('click',function() {...})

Now. When I change context and I creat dynamically new <div class="some_class"> the event is not binded enough. How I can solve this without repeating the binding in the context switch function ?

4

2 回答 2

2

利用

$(document).on('click','.some_class',function() {...})

代替

$('.some_class').on('click',function() {...})

有关详细信息,请参阅.on()

于 2013-03-15T17:51:46.343 回答
2

尝试使用:

$(document).on('click', '.some_class', function() {...})

反而

于 2013-03-15T17:51:52.340 回答