Decode HTML entities in JavaScript?

后端 未结 3 1575
情深已故
情深已故 2020-11-27 07:00

Sample conversions:

 & -> `&`
 >  -> `>`

Any small library function that can handle this?

3条回答
  •  囚心锁ツ
    2020-11-27 07:28

    Looks like this will do:

    function html_entity_decode(s) {
      var t=document.createElement('textarea');
      t.innerHTML = s;
      var v = t.value;
      t.parentNode.removeChild(t);
      return v;
    }
    

    Source

提交回复
热议问题