How to decode HTML entities using jQuery?

后端 未结 19 2569
忘了有多久
忘了有多久 2020-11-21 23:21

How do I use jQuery to decode HTML entities in a string?

19条回答
  •  情歌与酒
    2020-11-21 23:50

    Like Mike Samuel said, don't use jQuery.html().text() to decode html entities as it's unsafe.

    Instead, use a template renderer like Mustache.js or decodeEntities from @VyvIT's comment.

    Underscore.js utility-belt library comes with escape and unescape methods, but they are not safe for user input:

    _.escape(string)

    _.unescape(string)

提交回复
热议问题