HTML entities inside script tag not converted?

前端 未结 2 1739
情歌与酒
情歌与酒 2020-12-06 09:47



        
2条回答
  •  不思量自难忘°
    2020-12-06 10:17

    In HTML, script and style elements are defined in the DTD as containing CDATA. This means that entities and tags are ignored until the parser hits something that looks like an end tag.

    XHTML is different and entities and tags inside those elements function as normal — but only when parsed as XHTML. You can explicitly mark content as CDATA with .

    Browsers will treat XHTML served as text/html using HTML rules which leads to a big ball of nasty as you try to write code that is correct under both sets of rules.

    The simplest way to avoid problems is to keep scripts in external files and use the src attribute to include them.

提交回复
热议问题