How to decode HTML entities using jQuery?

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

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

19条回答
  •  说谎
    说谎 (楼主)
    2020-11-22 00:04

    You can use the he library, available from https://github.com/mathiasbynens/he

    Example:

    console.log(he.decode("Jörg & Jürgen rocked to & fro "));
    // Logs "Jörg & Jürgen rocked to & fro"
    

    I challenged the library's author on the question of whether there was any reason to use this library in clientside code in favour of the