html string refers to a string with html special symbols such as '
aklsdjfklsjdfl
'. We usually need to process it and then output it to prevent the output from becoming a real html element, that is, the html symbol code that changes < into <.
If the string is very long and contains many special symbols, how can we transcode them all simply and efficiently? cycle? Regular expression? No need! Let’s take a look:
function bian(a){return new Option(a).innerHTML}
That’s all!
How to use:
function bian(a){return new Option(a).innerHTML}
var a = '
aklsdjfklsjdfl
';
alert(bian(a));