最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to make text bold with sweetalert in 2018? - Stack Overflow

programmeradmin13浏览0评论

I saw that you could use the content option, but im not really sure how to go about that right now I have something like:

swal({title: 'hello', text: 'hello ${<strong>{name}</strong>}', icon: 'success' })

I saw that you could use the content option, but im not really sure how to go about that right now I have something like:

swal({title: 'hello', text: 'hello ${<strong>{name}</strong>}', icon: 'success' })

Share Improve this question asked Feb 19, 2018 at 18:51 Taylor AustinTaylor Austin 5,98716 gold badges63 silver badges108 bronze badges 2
  • 4 Try the same way that you used in 2017. It should work. ;) – Ricky Notaro-Garcia Commented Feb 19, 2018 at 18:53
  • I tried the html true and all that , but no success – Taylor Austin Commented Feb 19, 2018 at 18:58
Add a comment  | 

2 Answers 2

Reset to default 8

From the GitHub Issues, you should set a content and insert the text within it:

var name = "Stack Overflow";
var content = document.createElement('div');
    content.innerHTML = 'Hello <strong>'+ name +'</strong>';

    swal({
        title: 'Hello',
        content: content,
        icon: "success",
    })

Or, you can use SweetAlert2 - the supported fork of original SweetAlert:

Swal.fire({
  html: 'Overengineering is <strong>a bad thing</strong>'
})
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>

PS. notice that SweetAlert2 is a little bit different from SweetAlert, check the simple migration guide: https://github.com/sweetalert2/sweetalert2/wiki/Migration-from-SweetAlert-to-SweetAlert2

发布评论

评论列表(0)

  1. 暂无评论