V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
wework
V2EX  ›  程序员

sweetalert2 右上角关闭按钮如何修改?

  •  
  •   wework · 2020-05-21 10:02:57 +08:00 · 1903 次点击
    这是一个创建于 1435 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我第一次使用 https://github.com/sweetalert2/sweetalert2 做 modal 弹窗 ,引入了以下文件

    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/8.11.8/sweetalert2.min.css" />

    <script src="https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/8.11.8/sweetalert2.all.min.js"></script>

    然后 js 配置如下

    Swal.fire({
    title: data.title,
    html: data.html,
    type: "success",
    showCancelButton: false,
    showConfirmButton: false,
    showCloseButton: true
    })

    配置文件里面,我已经设置了显示关闭按钮,弹窗右上角确实有了那个按钮,但是默认按钮文本是 submit

    <button type="button" class="swal2-close" aria-label="Close this dialog" style="display: flex;">submit</button>

    我在官方文档那里好像找不到修改 关闭按钮文字的方法,有哪位朋友知道怎么修改么?
    6 条回复    2020-05-21 10:38:28 +08:00
    wework
        1
    wework  
    OP
       2020-05-21 10:20:24 +08:00
    哎,自己强制用 jquery 给他改值了 $(".swal2-close").text('X');
    w292614191
        2
    w292614191  
       2020-05-21 10:24:27 +08:00
    改源码
    或者
    buttonText 之类的。
    wework
        3
    wework  
    OP
       2020-05-21 10:29:12 +08:00
    @w292614191 没有 closeButtonText 的属性,超恶心的
    w292614191
        4
    w292614191  
       2020-05-21 10:31:21 +08:00
    这个看起来,挺好看的。17 年的时候用过一下下。
    w292614191
        5
    w292614191  
       2020-05-21 10:37:48 +08:00
    @wework

    closeButtonHtml
    这个属性,可以传入 html 。
    w292614191
        6
    w292614191  
       2020-05-21 10:38:28 +08:00
    @wework
    closeButtonHtml
    Use this to change the content of the close button.
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3323 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 12:31 · PVG 20:31 · LAX 05:31 · JFK 08:31
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.