Jquery 从
我需要使用jQuery删除选定表行的帮助Jquery 从,jquery,Jquery,我需要使用jQuery删除选定表行的帮助 <tr data-file='+file_id1+'> <td width="40%">'+file_name1+'</td> <td>'+upload_date1+'</td> <td><a href="sym.php?doc_id='+file_id1+'" class="view2_fl">VIEW FILE</a> | <
<tr data-file='+file_id1+'>
<td width="40%">'+file_name1+'</td>
<td>'+upload_date1+'</td>
<td><a href="sym.php?doc_id='+file_id1+'" class="view2_fl">VIEW FILE</a> | <a href="javascript:void(0);" class="del2_fl">DELETE</a></td>
</tr>
我删除这一行的尝试给我带来了问题,因为我似乎无法使用“this”找到它
感谢您的建议。默认情况下,在成功处理程序中,它绑定到$.ajaxSettings和您传递给$.ajax的选项的混合
您可以指定上下文选项将其绑定到您选择的对象,包括在调用者中绑定到的值。从那里,您只需要找到要删除的表行:
$.ajax({
type: "POST",
url: "admin_includes/del_fl.php",
data: file,
context: this, // Relay 'this' to 'success' handler.
success: function(html) {
if (html == "2") {
// Here, 'this' is the same as in the caller of '$.ajax()'.
$(this).closest("tr").remove();
}
}
});
虽然我想我没有说,在相同的表单中,用户有能力添加文件,但这确实有效。如果用户添加一个文件并决定删除该文件,则该文件不会消失。如果要删除的文件重复,则删除所有文件。然而,这取决于mysql,我现在已经更改了它。我现在的主要问题是删除我认为使用的附加文件。on可以解决这个问题。仅从您的评论来看,这个问题不容易理解。。。我建议你用更多信息更新你的问题来澄清这一点,张贴附加在文件后面的代码也是一个好主意。
$.ajax({
type: "POST",
url: "admin_includes/del_fl.php",
data: file,
context: this, // Relay 'this' to 'success' handler.
success: function(html) {
if (html == "2") {
// Here, 'this' is the same as in the caller of '$.ajax()'.
$(this).closest("tr").remove();
}
}
});