0

我不明白为什么livequery不绑定事件,但我必须使用.click. 这只是一个示例,它也可能使用 . .click(),但在实际代码中我被迫使用livequery. 有谁知道为什么livequery 不工作?

function bind_remove(comment){
    var id = comment.attr('comment_id');    
    comment.find(".remove").livequery("click", function(e){    
        $.post("/deleteComment", {id: id}, function(response){
            comment.remove();
            comments = comments_container.find('.comment');
        });    
    });
}

$(document).ready(function(){    

    var comments_container = $('#comments_container');
    var comments = comments_container.find('.comment');

    comments.each(function(){
        bind_remove($(this));
    });
    
    $(".submit_button").livequery("click", function(e){
    $.post("/newComment", {text: textarea.val()}, function(response){                    
        comments_container.last().append($(response).fadeIn('slow',function(){                    
                comments = comments_container.find('.comment');
                bind_remove(comments.last());                            
            }));
        });
    });
});
4

2 回答 2

0

尝试更换

comment.find(".remove").livequery("click", function(e){

有了这个

comment.find(".remove").live("click", function(e){
于 2011-03-27T17:10:53.940 回答
0

我在最后一条评论中添加了一个随机 ID,然后我用 $('#myid') 选择了它,而不是使用 'last()'。然后我绑定它并开始工作

于 2011-05-04T11:57:41.270 回答