【发布时间】:2016-08-25 01:54:16
【问题描述】:
我的列表中有一些链接可以触发一些 jQuery 活动:
HTML:
<div id="list">
<a href="#" rel="23" class="edit">Edit:</a> Foo
<a href="#" rel="24" class="edit">Edit:</a> Bar
etc.
查询:
$('.edit').click(function(e) {
e.preventDefault;
...open edit form and save update with $.ajax to server...
...with $.ajax retrieve fresh list from database...
...use $('#list;).html(fresh list of links)...
});
首先我尝试了以下方法将编辑链接“重新绑定”到一个事件:
$('.edit').on('click', function(...
那没用。在reading this great answer之后,我尝试了:
$(document).on('click', '.edit', function(...
还有宾果游戏!它奏效了。
问题:有人能解释一下两者的区别吗?
谢谢。
【问题讨论】: