首页 > 解决方案 > 运行甜蜜警报脚本时如何运行另一个 JavaScript 函数

问题描述

我想实现javascript函数来删除确认。单击ok确认警报表的按钮后,tr应从前端删除。我已经用于$("#confirm-btn-alert").click(function()确认警报,哪个在sweet-alert-script.jsfunction SomeDeleteRowFunction(o)​​个newfile.html用于删除tr

sweet-alert-script.js

$(document).ready(function(){
    $("#confirm-btn-alert").click(function(){

        swal({
            title: "Are you sure?",
            text: "Once deleted, you will not be able to recover this imaginary file!",
            icon: "warning",
            buttons: true,
            dangerMode: true,
        })
        .then((willDelete) => {
            if (willDelete) {
                swal("Poof! Your imaginary file has been deleted!", {
                    icon: "success",
                });
            } else {
                swal("Your imaginary file is safe!");
            }
        });

    });

});

新文件.html

<script>
    function SomeDeleteRowFunction(o) {
        var p=o.parentNode.parentNode;
        p.parentNode.removeChild(p);
    }
</script>

标签: javascript

解决方案


您可以尝试与单击确认按钮相同的方法!用以下内容
更改<script> function

$(document).ready(function(){
    $("#ok-button-id").click(function(o){
        var p=o.parentNode.parentNode;
        p.parentNode.removeChild(p);
    })
});



或者,如果<tr>有身份证,这对你来说很容易。
<tr id="myTableRow"><td>Confirmation message here</td></tr>

$(document).ready(function(){
    $("#ok-button-id").click(function(){
         $('#myTableRow').remove();
    })
});


这是另一种方式

 $(document).ready(function(){
    $('#myTableID tr').click(function(){ //Here 'this' will be the table row
        $(this).remove();
        return false;
    })
});

推荐阅读