我正在我正在创建的页面中实现“快速删除”功能。它的工作方式是这样的:
1:单击要删除的记录所在表格行中的“删除”按钮。
2:页面向ajax页面发送请求,成功返回“yes”,失败返回“no”。
我的问题是,如果我收到"is"的成功消息,我想隐藏该记录的行。我在使用 JQuery“查找”行时遇到问题。
这是我的 jquery 代码:
$(document).ready(function(){
$(".pane .btn-delete").click(function(){
var element = $(this);
var del_id = element.attr("id");
var dataString = 'action=del&cid=' + del_id;
if(confirm("Are you sure you want to delete this content block?"))
{
$("#msgbox").addClass('ajaxmsg').text('Checking permissions....').fadeIn(1000);
$.ajax({
type: "get",
url: "ajax/admArticles_ajax.php",
data: dataString,
success: function(data){
switch(data)
{
case "yes":
$("#msgbox").addClass('ajaxmsg').text('Deleting content block....').fadeIn(1000);
$(this).parents(".pane").animate({ backgroundColor: "#fbc7c7" }, "fast")
.animate({ opacity: "hide" }, "slow")
break
case "no":
$("#msgbox").removeClass().addClass('error').text('You do not have the correct permissions to delete this content....').fadeIn(1000);
break
default:
};
}
});
}
return false;
});
});
这是我用来隐藏行的代码行,但它不起作用,因为我认为 $(this).parents(".pane") 找不到该元素。
$(this).parents(".pane").animate({ backgroundColor: "#fbc7c7" }, "fast")
.animate({ opacity: "hide" }, "slow")
任何帮助将不胜感激。谢谢...
最佳答案
在 Ajax 回调中,this
不会引用处理该事件的元素。
不过,您已经在名为 element
的事件处理程序中引用了它。只要这样做:
element.parents(".pane").animate({ backgroundColor: "#fbc7c7" }, "fast")
.animate({ opacity: "hide" }, "slow")
关于JQuery ajax成功帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2741532/