html string refers to a string with html special symbols such as '<div id=”a”>aklsdjfklsjdfl</div>'. We usually have to process it and then output it to avoid outputting it into a real html element, that is, turning < into < such an html symbol code.
If the string is very long and there are many special symbols inside, how can we transcode them all simply and efficiently? cycle? Regular expression? No need! Let's see:
The code copy is as follows:
function bian(a){return new Option(a).innerHTML}
That's it all!
How to use:
The code copy is as follows:
function bian(a){return new Option(a).innerHTML}
var a = '<div id="a">aklsdjfklsjdfl</div>';
alert(bian(a));