DOM插入后不会绑定livequery
问题描述:
我不明白为什么livequery不绑定事件,但我必须使用.click 这只是一个示例,它也可能使用.click(),但在实际的代码中,我不得不使用livequery。 有谁知道为什么livequery不工作?DOM插入后不会绑定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());
}));
});
});
});
答
我添加了一个随机ID,以最后一个注释更换
comment.find(".remove").livequery("click", function(e){
,然后我用$( '#身份识别码')来选择它,而不是使用'持续()'。然后我绑定它并开始工作
你使用的是什么版本的jQuery? – 2011-03-28 03:34:47
我试过版本1.4.4和版本1.5.1 – rodi 2011-03-28 11:02:50