V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
wework
V2EX  ›  程序员

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

  •  
  •   wework · May 21, 2020 · 2559 views
    This topic created in 2177 days ago, the information mentioned may be changed or developed.
    我第一次使用 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 replies    2020-05-21 10:38:28 +08:00
    wework
        1
    wework  
    OP
       May 21, 2020
    哎,自己强制用 jquery 给他改值了 $(".swal2-close").text('X');
    w292614191
        2
    w292614191  
       May 21, 2020
    改源码
    或者
    buttonText 之类的。
    wework
        3
    wework  
    OP
       May 21, 2020
    @w292614191 没有 closeButtonText 的属性,超恶心的
    w292614191
        4
    w292614191  
       May 21, 2020
    这个看起来,挺好看的。17 年的时候用过一下下。
    w292614191
        5
    w292614191  
       May 21, 2020
    @wework

    closeButtonHtml
    这个属性,可以传入 html 。
    w292614191
        6
    w292614191  
       May 21, 2020
    @wework
    closeButtonHtml
    Use this to change the content of the close button.
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3637 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 61ms · UTC 05:01 · PVG 13:01 · LAX 22:01 · JFK 01:01
    ♥ Do have faith in what you're doing.