从表中的链接中选择一行时遇到问题。当链接被点击时,我需要该行消失。我当前的代码如下。。。
function show_docs(){
$('.file_holder5').html("");
var id=$('.useri').val();
var data="user_id="+id;
$.ajax({
type:"POST",
url:"admin_includes/get_all_files.php",
data:data,
success:function(html){
var split_html=html.split("*^*");
var split_ht_count=split_html.length-1;
var tb2="<table class='doc_table' width='100%'>";
tb2+="<tr><th>Upload Date</th><th>File</th><th>Description</th><th>Actions</th><th> </th></tr>";
var el;
if(split_ht_count==0)
{
tb2+="</table>";
tb2+="<p>There are currently no files in your library.</p>";
}
else
{
for(var rx=0;rx<split_ht_count;rx++)
{
el=split_html[rx].split("|");
tb2+="<tr class='file_row' data-link2='"+el[0]+"'><td>"+el[2]+"</td><td>"+el[1]+"</td><td>"+el[3]+"</td><td><a class='view_f' href='sym.php?doc_id="+el[0]+"'>View File</a></td><td><a class='del_f' href='javascript:void(0)' data-link='"+el[0]+"'>Delete File</a></td></tr>";
}
tb2+="</table>";
}//end else
$(tb2).appendTo('.file_holder5');
StripeRows();
}
});//end ajax
}
//-----------------delete_files---------------------
$(document).on('click', '.del_f', function(){
var file_id=$(this).data('link');
var data="file_id="+file_id+"&user="+$('.useri').val();
$.ajax({
type:"POST",
url:"admin_includes/delete_filex.php",
data:data,
context:this,
success:function(html){
if(html=="1")
{
alert("The selected file is needed for a current job. To delete this file, delete the file from the current appointment in the Current Jobs page.");
return;
}
else
{
//get rid of listing
$('tr.file_row').data('link2', file_id).remove();
}
}
});//end ajax
});
显然,正是我选择当前行的方法给我带来了问题。
当您尝试删除行时,请尝试以下代码:
$(this).closest("tr").remove();
请参阅jsFiddle
$('.deleteRowButton').click(function () {
$(this).parents('tr').first().remove();
});