前端【参考】CDATA 去除转义符号

 

web标准使用方法

根据W3C XHTML 1.0的规定:在XHTML中,因为<和&这两个符号有特殊意义(小于号用于标签的开始标记),所以这两个符号<和&需要转义成<和&。

 

比如下面的XHTML标准模式代码是错误,因为未使用转义字符:




    
    test
    


xhtml,It works.

 

有两种方法能够解决这个问题

1.工作在html模式下,向新兼容XML解析器(即符合XML语法),使用下面的代码:




    
    test
    


html,It works.

 

2.工作在html模式下,不兼容XML解析器(来自http://www.w3.org/TR/html401/interact/scripts.html#h-18.3.2)




    
    test
    


html,It works.

 

为什么说上面这段代码不兼容XML解析器呢?

请看:http://www.w3.org/TR/2002/REC-xhtml1-20020801/#C_4

W3C的解释是:Note that XML parsers are permitted to silently remove the contents of comments. Therefore, the historical practice of "hiding" scripts and style sheets within "comments" to make the documents backward compatible is likely to not work as expected in XML-based user agents.

即:在XML语法中,     

xhtml,It works.

 

 

你可能感兴趣的:(前端,前端,js,CDATA)