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

2020-05-21 10:02:57 +08:00
 wework
我第一次使用 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>

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

closeButtonHtml
这个属性,可以传入 html 。
w292614191
2020-05-21 10:38:28 +08:00
@wework
closeButtonHtml
Use this to change the content of the close button.

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/673878

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX