我使用以下脚本对博客上的帖子点赞
$('.like-unlike').on('click',function() {
if ($(this).html() == " Like ") {
postID = this.id.replace('post_', '');
$.ajax({
url: 'auth/classes/comments.php',
type: 'GET',
data: 'token=<?php echo $token; ?>&post='+escape(postID)+'&like=yes',
success: function(data) {
console.log(data);}
});
$('.right#stats_'+postID).text(function (idx, text) {
text = $.trim(text);
var count = parseInt(text.match(/^(\d+)/), 10) || 0;
return text.replace(/^\d+/, ++count);
});
$(this).html(' Liked ');
}
我实现了一个分页脚本,该脚本在页面加载后向服务器发送请求,以便在文档下载后将内容添加到页面。现在我喜欢的脚本不起作用。如果我在它运行的 Firebug ,请帮助
最佳答案
尝试:
$('body').on('click','.like-unlike',function() {
...
});
关于javascript - 加载文档后添加内容时不执行 Jquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20250821/