javascript - 为什么人们在他们的 javascript 代码周围添加 <!--//...//--> ?

标签 javascript

我记得几年前读过一些相关内容,但我现在不记得了。

这是否与 IE 并将其解析为纯文本有关...?

最佳答案

我认为你的意思是CDATA

source

This fixes the validator. The problem is that some older web browsers don't understand the CDATA tag and so this breaks your Javascript in those web browsers. Fortunately, Javascript multi-line comments start and finish with characters that do not cause validation errors. We can therefore comment out the CDATA tag in so far as the Javascript processors within the web browsers are concerned while still leaving the Javascript content defined as CDATA as far as the validator is concerned. We do it like this:

<script type="text/javascript">
/* <![CDATA[ */
// content of your Javascript goes here
/* ]]> */
</script>

关于javascript - 为什么人们在他们的 javascript 代码周围添加 &lt;!--//...//--> ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10988791/

相关文章:

php - 通过 json_encode 使用 php 填充 highcharts

javascript - iOS Safari/Chrome - 在模态内聚焦输入时不需要的滚动

javascript - 将 meteor 应用程序部署到模数的问题

javascript - 如何检测 ember 数据中的新记录是否已更改

javascript - react 中的脚本加载

javascript - IE 对象不支持此属性或方法

javascript - 使用 Javascript 滚动 DIV 容器内的 DIV

javascript - 错误 : cannot call function of deleted QObject

javascript - 将 (object.function) 作为参数传递

javascript - 为什么我的增量器返回一个对象? id_[对象 HTMLInputElement]