我不明白为什么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());
}));
});
});
});
答案 0 :(得分:0)
尝试替换
comment.find(".remove").livequery("click", function(e){
用这个
comment.find(".remove").live("click", function(e){
答案 1 :(得分:0)
我在最后一条评论中添加了一个随机ID,然后我用$('#myid')选择它,而不是使用'last()'。然后我绑定它并开始工作