繁体   English   中英

表单提交后在表格内隐藏按钮?

[英]Hide button inside a table after form submit?

因此,我试图在按Delete后使包含删除按钮的行隐藏到.hide中。 问题是..删除按钮提交了一个表单,我无法预定义我的按钮类/ ID,因为它多次被蜂鸣(PHP脚本读取一个目录,然后将所有文件放在表中)

这是当前的脚本,它确实在后台发布了表单,但是它没有隐藏元素,我自己尝试了一些东西,但是脚本最终隐藏了页面上的所有按钮,或者根本无法工作..

按钮蜂鸣回声:

echo "<input type='submit' value='delete' name='submit'>";

其背后的脚本:

$("#delform").submit(function() {

    var url = "../../setdel.php"; // the script where you handle the form input.

    $.ajax({
           type: "POST",
           url: url,
           data: $("#delform").serialize(), // serializes the form's elements.
           success: function(data)
           {
             // location.reload(); // show response from the php script.
           }
         });

    return false; // avoid to execute the actual submit of the form.
});

捕获按钮的onclick而不是捕获提交。 例:

echo "<input type='submit' value='delete' name='delete' class='trigger_delete'>";
                                            //  ^^ don't name your buttons as submit
                                            // it will conflict to .submit() method

在JS上:

$('.trigger_delete').on('click', function(e){
    e.preventDefault(); // prevent triggering submit
    var url = "../../setdel.php";

    $.ajax({
        type: 'POST',
        url: url,
        data: $("#delform").serialize(),
        success: function(response) {
            console.log(response);
            $(e.target).closest('tr').hide(); // or .fadeOut();
        }(e) // <--- this one
     });
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM