Javascript 加载文档后添加内容时不执行Jquery

Javascript 加载文档后添加内容时不执行Jquery,javascript,php,jquery,events,bing,Javascript,Php,Jquery,Events,Bing,我使用下面的脚本在博客上的帖子上发表喜欢的内容 $('.like-unlike').on('click',function() { if ($(this).html() == " Like ") { postID = this.id.replace('post_', ''); $.ajax({ url: 'auth/classes/comments.php', type

我使用下面的脚本在博客上的帖子上发表喜欢的内容

$('.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('&nbsp;Liked&nbsp;');
    }
$('.like-inspect')。在('click',function()上{
if($(this.html()==“Like”){
postID=此.id.replace('post_','');
$.ajax({
url:'auth/classes/comments.php',
键入:“GET”,
数据:'token=&post='+escape(postID)+'&like=yes',
成功:功能(数据){
console.log(数据);}
});
$('.right#stats_'+postID).text(函数(idx,text){
text=$.trim(text);
var count=parseInt(text.match(/^(\d+/),10)| 0;
返回文本。替换(/^\d+/,+++count);
});
$(this.html('Liked');
}
我实现了一个分页脚本,该脚本在页面加载后向服务器发送请求,以便在文档下载后将内容添加到页面中。现在,我喜欢的脚本不起作用。如果我在firebug上运行此脚本,请提供帮助。

尝试:

$('body').on('click','.like-unlike',function() {
    ...
});

将事件处理程序更改为委托样式-

$('body').on('click', '.like-unlike', function() {

你应该用谷歌搜索你的标题,有上百个相关答案…谢谢…我不知道..如何使用$(document).ready(function(){$(“.comment_box”).hide()})..采用这种格式?这样即使在文档下载后添加了注释框,它也会隐藏注释框?不,只有页面加载时可见的注释框才会隐藏。添加的任何其他注释框都会显示,除非您再次隐藏它们-有没有办法在文档加载后隐藏所有注释框类?@user3038421:使用CSS.Thanks…不知道..如何使用$(document).ready(function(){$(“.comment_box”).hide();}..这种格式?这样即使在文档下载后添加了注释_box,它也会隐藏注释_box?–如果您有新问题,请单独发布。
$('body').on('click', '.like-unlike', function() {