如何在laravel中显示弹出警报

问题描述 投票:0回答:1

在我的数据库中,我有一个名为tasks的表,它有一个名为file的列,用于存储文件。现在我想当用户单击文件时,他将显示一条弹出消息,询问您是否下载或查看文件。

部分尝试这样

<a href="" id="popup">{{ $task->file }}

并且我为此创建了一个甜蜜的消息,如下所示

$(document).ready(function () {
          $('popup').on('click', 'td.warning input', function () {
            Swal.fire({
                    title: "Wow!",
                    text: "Message!",
                    type: "success",
                    showCancelButton: true,
                    cancelButtonText: "View",
                    confirmButtonText: 'Download!',
                },
                function (isConfirm) {
                    if (isConfirm) {
                        swal("Deleted!", "Your imaginary file has been deleted!", "success");
                    } else {
                        swal("Cancelled", "Your imaginary file is safe :)", "error");
                    }
                });
          });
      });
    </script

请帮助我实现这一目标

javascript jquery laravel sweetalert2
1个回答
0
投票

向甜蜜警报添加一些html代码,因此您可以显示消息或图像,就像我在这里所做的那样,您可以查看文档以获取更多示例性操作:https://sweetalert2.github.io/

<a href="" id="popup">{{ $task->file }}
<script>
$(document).ready(function () {
          $('popup').on('click', 'td.warning input', function () {
            Swal.fire({
                    title: "Wow!",
                    text: "Message!",
                    type: "success",
                    showCancelButton: true,
                    cancelButtonText: "View",
                    confirmButtonText: 'Download!',
                },
                function (isConfirm) {
                    if (isConfirm) {
                        swal("Deleted!", "Your imaginary file has been deleted!", "success");
                    } else {
                        swal("Cancelled", "Your imaginary file is safe :)", "error");
                    }
                });
          });
      });
    </script>

然后您可以通过添加if和else swal的一些html代码来添加甜蜜的警报,某种消息传递:

if (isConfirm) {
        swal(
        title:"Deleted!", 
        text: "Your imaginary file has been deleted!",
        type: "success",
        html: '<h1>Text here to download or to view</h1>'+
        '<p>show some more text or show image</p>'
        );
} else {
        swal(
        title:"Cancelled", 
        text: "Your imaginary file is safe :)", 
        type: "error",
        html: '<h1>Text here to download or to view</h1>'+
        '<p>show some more text or show image</p>'
);
}

希望这对您有用...

© www.soinside.com 2019 - 2024. All rights reserved.