2012-09-06 60 views
2

我無法從行內的鏈接中選擇一行表格。當鏈接被點擊時,我需要該行消失。我目前的代碼如下...JQuery從表格中的鏈接中刪除表格行

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>&nbsp;</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 
}); 

很明顯,這是我選擇當前行導致我的問題的方法。

+1

莫非你過去你的表的HTML的一部分嗎? – gotqn

回答

3

當您嘗試刪除該行試試這個代碼:

$(this).closest("tr").remove(); 
+0

工作正常 - 謝謝:) – Sideshow

0

看到jsFiddle

$('.deleteRowButton').click(function() { 
    $(this).parents('tr').first().remove(); 
});