What exactly do I have to escape inside a `script` element?

后端 未结 3 1366
轻奢々
轻奢々 2020-12-16 00:28

What parts of JavaScript code do I have to escape inside a script element in a HTML page? Is <>& enough or too much?

[EDI

3条回答
  •  悲哀的现实
    2020-12-16 01:11

    Generally, the only thing I escape is the / in closing tags. Thus:

    var msg = "

    Do you really<\/em> think so, Miss Worthington?<\/p>";

    For the rest, I rely on commenting out the entire thing:

    
    

    The comment takes care of the HTML opening tags.

提交回复
热议问题