【发布时间】:2012-12-22 11:25:19
【问题描述】:
我有几行列出这个脚本
$("a.remove").click(function(){
var id = $(this).attr('id')
var user = $(this).attr('value')
$.ajax({
success : function(){
var url = "includes/action.php?page=access&action=remove";
var popupmessage = "Error";
$.post(url, { id: id },
function(data){
return true;
});
}
});
});
但是当我通过 jQuery 添加新行时,它在刷新页面之前不起作用
$("<a class=\"remove\" href=\"#\"></a>").insertAfter('#accesstable tr:last');
知道怎么解决吗?
编辑: 工作代码
$('a.remove').live('click', function(){
var id = $(this).attr('id')
var user = $(this).attr('value')
$.ajax({
success : function(){
var url = "includes/action.php?page=access&action=remove";
var popupmessage = "Error";
$.post(url, { id: id },
function(data){
return true;
});
}
});
});
【问题讨论】:
-
什么不起作用?会发生什么?
-
我不知道
I have few line that listing to this script或add new line via jQuery是什么意思,所以……是啊…… -
您的选择器看起来很糟糕。改用
$('a.remove').click(function(){})和$('#' + rid).insertAfter('#accesstable tr:last') -
是的,我知道.. 这是旧的 שbandoned 代码。我会优化它,谢谢
-
**不要使用
live,因为它已被弃用。我建议你看看@matt 的回答:stackoverflow.com/questions/14217865/…