When is a CDATA section necessary within a script tag?

后端 未结 15 2296
时光说笑
时光说笑 2020-11-21 22:37

Are CDATA tags ever necessary in script tags and if so when?

In other words, when and where is this:



        
15条回答
  •  别那么骄傲
    2020-11-21 23:02

    It's an X(HT)ML thing. When you use symbols like < and > within the JavaScript, e.g. for comparing two integers, this would have to be parsed like XML, thus they would mark as a beginning or end of a tag.

    The CDATA means that the following lines (everything up unto the ]]> is not XML and thus should not be parsed that way.

提交回复
热议问题