admin 管理员组文章数量: 1087564
Using node.innerHTML = "abcxyz <[email protected]>";
makes the browser display something just the “abcxyz” part – the rest is seemingly ignored because of the angle brackets (<>
). How to ensure they show on the page?
Using node.innerHTML = "abcxyz <[email protected]>";
makes the browser display something just the “abcxyz” part – the rest is seemingly ignored because of the angle brackets (<>
). How to ensure they show on the page?
5 Answers
Reset to default 10Actually, the content is still there, but the browser interprets it as unknown tag, that is, it does not display anything. Look at the generated page source (in FF, e.g., mark all text and use "Selection source" from the context menu).
Try quoting the brackets:
obj.innerHTML = "abcxyz <[email protected]>".replace (/</g, "<")
This, however, will replace all <
. If you want to embed other HTML, too, you will have to keep track on what you already encoded and what not.
Cheers,
HTML encode your string or use HTML entities such as <
In HTML, a literal "<" is represented as "<" and a literal ">" is represented as ">". See HTML 4.01 section 5.3.2.
I would try this: unescape('abcxyz %3Cabc...
You need to escape < and > in string.
本文标签:
版权声明:本文标题:javascript - How to ensure HTML-sensitive characters (less-than sign, ampersand, etc.) are displayed as text when assigning to ` 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744035412a2522274.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论