How to decode HTML entities using jQuery?

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

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

19条回答
  •  有刺的猬
    2020-11-22 00:07

    Use

    myString = myString.replace( /\&/g, '&' );
    

    It is easiest to do it on the server side because apparently JavaScript has no native library for handling entities, nor did I find any near the top of search results for the various frameworks that extend JavaScript.

    Search for "JavaScript HTML entities", and you might find a few libraries for just that purpose, but they'll probably all be built around the above logic - replace, entity by entity.

提交回复
热议问题