问题
Possible Duplicate:
JavaScript/jQuery HTML Encoding
I have html tags need to be encoded.
<b>test</b>
I need to encode it to :
<b>test</b>
I am using escape, but it doesn't work.
document.write(escape("<b>test</b>"));
the result I got is
%3Cb%3Etest%3C/b%3E
this is not what I expected. is there another way to do html encode using javascript?
回答1:
var html = "<b>test</b>";
var result = html.replace(/</g,"<").replace(/>/g,">");
来源:https://stackoverflow.com/questions/14346414/how-do-you-do-html-encode-using-javascript