开发者

Is there any method to unescape '>' to '>' in JavaScript?

i want to escape some HTML in Ja开发者_StackOverflow中文版vaScript. How can I do that?


I often use the following function to decode HTML Entities:

function htmlDecode(input){
  var e = document.createElement('div');
  e.innerHTML = input;
  return e.childNodes[0].nodeValue;
}

htmlDecode('&lt;&gt;'); // "<>"

Simple, cross-browser and works with all the HTML 4 Character Entities.


You could create a dummy textarea, set its innerHTML to your escaped html [the html with &gt;s] and use the textarea.value

var ta = document.createElement('textarea');
 ta.innerHTML = "&gt;";
 alert(ta.value);

... had to use this on a CMS once [although when i used it, it was bad practice]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜