如何在 2018 年使用 sweetalert 将文本加粗?
How to make text bold with sweetalert in 2018?
我看到您可以使用内容选项,但我现在不太确定如何去做,我有类似的东西:
swal({title: 'hello', text: 'hello ${<strong>{name}</strong>}', icon: 'success' })
在 GitHub 问题中,您应该设置一个内容并在其中插入文本:
var name = "Stack Overflow";
var content = document.createElement('div');
content.innerHTML = 'Hello <strong>'+ name +'</strong>';
swal({
title: 'Hello',
content: content,
icon: "success",
})
或者,您可以使用 SweetAlert2 - 支持原始 SweetAlert 的分支:
Swal.fire({
html: 'Overengineering is <strong>a bad thing</strong>'
})
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
PS。请注意 SweetAlert2 与 SweetAlert 略有不同,查看简单迁移指南:https://github.com/sweetalert2/sweetalert2/wiki/Migration-from-SweetAlert-to-SweetAlert2
我看到您可以使用内容选项,但我现在不太确定如何去做,我有类似的东西:
swal({title: 'hello', text: 'hello ${<strong>{name}</strong>}', icon: 'success' })
在 GitHub 问题中,您应该设置一个内容并在其中插入文本:
var name = "Stack Overflow";
var content = document.createElement('div');
content.innerHTML = 'Hello <strong>'+ name +'</strong>';
swal({
title: 'Hello',
content: content,
icon: "success",
})
或者,您可以使用 SweetAlert2 - 支持原始 SweetAlert 的分支:
Swal.fire({
html: 'Overengineering is <strong>a bad thing</strong>'
})
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
PS。请注意 SweetAlert2 与 SweetAlert 略有不同,查看简单迁移指南:https://github.com/sweetalert2/sweetalert2/wiki/Migration-from-SweetAlert-to-SweetAlert2