【问题标题】:How to show a popup alert in laravel如何在laravel中显示弹出警报
【发布时间】:2020-02-22 11:10:27
【问题描述】:

在我的数据库中,我有一个名为 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】:

    在甜蜜警报中添加一些 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>'
    );
    }
    

    希望这对你有用...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-02-05
      • 1970-01-01
      • 2013-08-27
      • 2021-02-11
      • 2019-08-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多