Unescape HTML entities in Javascript?

前端 未结 30 2937
野趣味
野趣味 2020-11-21 05:40

I have some Javascript code that communicates with an XML-RPC backend. The XML-RPC returns strings of the form:


30条回答
  •  盖世英雄少女心
    2020-11-21 05:43

    Chris answer is nice & elegant but it fails if value is undefined. Just simple improvement makes it solid:

    function htmlDecode(value) {
       return (typeof value === 'undefined') ? '' : $('
    ').html(value).text(); }

提交回复
热议问题