我不明白为什么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());
}));
});
});
});发布于 2011-05-04 19:57:41
我给最后一个评论添加了一个随机的id,然后我用$('#myid')选择了它,而不是使用' last ()‘。然后我绑定了它并开始工作
发布于 2011-03-28 01:10:54
尝试替换
comment.find(".remove").livequery("click", function(e){有了这个
comment.find(".remove").live("click", function(e){https://stackoverflow.com/questions/5450786
复制相似问题