Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Document.getElementById(…)在Laravel视图中为空_Javascript_Laravel_Laravel Blade - Fatal编程技术网

Javascript Document.getElementById(…)在Laravel视图中为空

Javascript Document.getElementById(…)在Laravel视图中为空,javascript,laravel,laravel-blade,Javascript,Laravel,Laravel Blade,控制台中的消息 TypeError:document.getElementById(…)为空 刀片(包含要删除的按钮) i class=“fa fa垃圾”> @csrf @方法('DELETE') Javascript实现 <script> function deleteSaleItem(id){ const swalWithBootstrapButtons = swal.mixin({ confirmButtonClass: 'btn

控制台中的消息

TypeError:document.getElementById(…)为空

刀片(包含要删除的按钮)


i class=“fa fa垃圾”>
@csrf
@方法('DELETE')
Javascript实现

<script>

    function deleteSaleItem(id){
        const swalWithBootstrapButtons = swal.mixin({
        confirmButtonClass: 'btn btn-success',
        cancelButtonClass: 'btn btn-danger',
        buttonsStyling: false,
        })

        swalWithBootstrapButtons({
        title: 'Are you sure?',
        text: "You won't be able to revert this!",
        type: 'warning',
        showCancelButton: true,
        confirmButtonText: 'Yes, delete it!',
        cancelButtonText: 'No, cancel!',
        reverseButtons: true
        }).then((result) => {
        if (result.value) {
            event.preventDefault();
            document.getElementById('delete-form-'+id).submit();
        } else if (
            // Read more about handling dismissals
            result.dismiss === swal.DismissReason.cancel
        ) {
            swalWithBootstrapButtons(
            'Cancelled',
            'Your data is safe :)',
            'error'
            )
        }
        })
    }
</script>

函数项(id){
const swalWithBootstrapButtons=swal.mixin({
confirmButtonClass:'btn btn success',
取消按钮类:“btn btn危险”,
按钮样式:false,
})
swalWithBootstrapButtons({
标题:“你确定吗?”,
文本:“您将无法还原此内容!”,
键入:“警告”,
showCancelButton:true,
confirmButtonText:'是,删除它!',
cancelButtonText:'不,取消!',
反转按钮:真
})。然后((结果)=>{
if(result.value){
event.preventDefault();
document.getElementById('delete-form-'+id).submit();
}否则如果(
//了解更多有关处理解雇的信息
result.dismise===swal.DismissReason.cancel
) {
swalWithBootstrapButtons(
“取消”,
“您的数据是安全的:)”,
“错误”
)
}
})
}

我需要知道这个导致null的代码有什么问题。谢谢。

您的代码中只有一个getElementById

document.getElementById('delete-form-'+id)
因此,可能是“id”变量为空或null,并且您检索的元素变为null


请尝试在document.getElementById代码之前调试或console.log您的'id'变量,以查看变量发生了什么变化

你为什么不把这个按钮放在表单里面,听听表单的“on subit”事件呢?当我通过控制台登录id时,它会显示确切的id号