JQuery 从表内的链接删除表行

标签 jquery jquery-selectors

我无法从行内的链接选择表中的一行。单击链接时,我需要该行消失。我当前的代码如下...

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
 });

显然是我选择当前行的方法给我带来了问题。

最佳答案

当您尝试删除该行时,请尝试以下代码:

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

关于JQuery 从表内的链接删除表行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12297311/

相关文章:

javascript - 如果电子邮件输入处于焦点状态,则阻止输入按钮表单提交(jquery)

jquery-selectors - 深入了解 Jquery 选择器

jquery - 在不刷新页面的情况下链接到 HTML 页面顶部

javascript - 图表拦截触摸事件并防止在 c3 js 中滚动

jquery - 根据属性值隐藏元素

javascript - jquery 选择器出现问题

javascript - 通过对象解析

javascript - jQuery 选择器性能

javascript - 单击父 div 时,获取子值 - 无需字符串操作

Ajax 前提条件失败错误