IE11 does not escape a concatenated “<” charact

2019-08-06 10:17发布

问题:

I have a string, say hello <whatever>, how are you?. When I check the "page source", I get proper rendering of that string (with special characters converted).

However, if I try to read that string and put it on a pop-up window message, the message will read hello , how are you?. If I place a space after the < character (i.e.: hello < whatever >, how are you?), the pop-up message displays correctly: hello < whatever >, how are you?.

How can I properly escape the < character so that the entire text gets read properly? &lt; and &064; does not do the trick (remember that they are properly converted anyway).

Summary: any string that has a < special character followed by any alphabetical character without any blank space in between cannot be properly read by IE(11).

Edit: As soon as I posted this question, you can see what I mean by reading the first sentence. It shows as hello , how are you? even though I typed hello < whatever>, how are you? with no space between the < character and whatever.

回答1:

You need to use HTML character encoding:

&lt; for <

&gt; for >

See the W3C's Character Entity Reference Chart for more information.