我看到您可以使用 content 选项,但我现在不太确定该怎么做。我有以下代码:
swal({title: 'hello', text: `hello ${<strong>{name}</strong>}`, icon: 'success' })
swal({title: 'hello', text: `hello ${<strong>{name}</strong>}`, icon: 'success' })
Swal.fire({
html: 'Overengineering is <strong>a bad thing</strong>'
})
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
注意:SweetAlert2与SweetAlert略有不同,请查看简易迁移指南:https://github.com/sweetalert2/sweetalert2/wiki/Migration-from-SweetAlert-to-SweetAlert2
从GitHub Issues中,您应该设置一个内容并在其中插入文本:
var name = "Stack Overflow";
var content = document.createElement('div');
content.innerHTML = 'Hello <strong>'+ name +'</strong>';
swal({
title: 'Hello',
content: content,
icon: "success",
})