jquery live方法的问题
我有类似墙柱的东西,可以选择“删除”。由于可以随时添加帖子,因此我使用 jquery live 方法进行事件处理。 问题是,多个事件附加到点击事件上的“删除”
$(document).ready(function(){
$('.actions .remove_wall_post').live('click', function(){
var wall_post_id = $(this).attr('id');
var data = {
'action' : 'remove',
'wall_post_id' : wall_post_id
};
var url = myurl;
$.post(url, data, function(response){
if(response == '1'){
$('#post_list #'+wall_post_id).hide();
var total_posts = $('#total_posts').text();
} else{
alert('ERROR');
}
});
return false;
});
});
假设有n个帖子,当我点击任何帖子的“删除”时,第一个事件工作正常......但之后我收到n个错误警报并且所有事件都有相同的 wall_post_id
I have something like wall posts which have the option of 'remove'. Since posts can be added any time hence I'm using jquery live method for event handling.
The problem is, multiple events are getting attached to 'remove' on click event
$(document).ready(function(){
$('.actions .remove_wall_post').live('click', function(){
var wall_post_id = $(this).attr('id');
var data = {
'action' : 'remove',
'wall_post_id' : wall_post_id
};
var url = myurl;
$.post(url, data, function(response){
if(response == '1'){
$('#post_list #'+wall_post_id).hide();
var total_posts = $('#total_posts').text();
} else{
alert('ERROR');
}
});
return false;
});
});
Suppose there are n posts, when I click on 'remove' of any post, the first event works fine...but after that i get n ERROR alerts and all events have the same wall_post_id
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论