我用query load function.更新了主页中的帖子,它使我能够显示实际的帖子。然而,我有一个问题。也就是说:当我在没有刷新整个页面的情况下更新所有帖子时,我想控制加载了load jquery函数的元素。我用这个加载了所有实际的帖子:
$( ".all-posts" ).load("/ .all-posts");.all-posts元素由.post-edit class name.组成
我想通过这个函数找到:
$('.post-edit').click(function(){
alert("found element");
});我修复了这个问题:我在load函数之外定义了函数,并且在load函数的回调函数中正常地使用了它。
发布于 2019-04-05 20:38:35
您可以使用event delegation。
替换:
$('.post-edit').click(function(){
alert("found element");
});通过以下方式:
$('.all-posts').on('click', '.post-edit', function () {
alert("found element");
});https://stackoverflow.com/questions/55535503
复制相似问题