javascript - <!-- 在 Javascript 中是做什么的?

标签 javascript symbols

在 Google 中搜索符号非常困难,所以我在这里问。

<!--看起来像是对我的评论,但它不像 html 那样工作。或者像 // 这样的单行注释?

使用它的目的和好处是什么?谢谢

示例代码:

<script type="text/javascript">
<!--
    alert("example");
//-->
</script>

最佳答案

这是一种从浏览器中隐藏 JavaScript 的旧方法,它会处理 script 的文本节点。元素作为普通文本(并显示您的代码)。

Douglas Crockford recommends你不再使用它了。

Do not use the <!-- //--> hack with scripts. It was intended to prevent scripts from showing up as text on the first generation browsers Netscape 1 and Mosaic. It has not been necessary for many years. <!-- //--> is supposed to signal an HTML comment. Comments should be ignored, not compiled and executed. Also, HTML comments are not to include --, so a script that decrements has an HTML error.

关于javascript - &lt;!-- 在 Javascript 中是做什么的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5932585/

相关文章:

javascript - 此回调函数未定义

java - 谁能告诉我为什么这在 Eclipse 中有效但在命令提示符中不起作用?

c# - 在 C# 中, "symbol"究竟被归类为什么?

javascript - 使用 native 文件系统 API 在 Windows 资源管理器中打开文件夹

JavaScript 对象依赖于另一个对象

javascript - 点击前点击事件触发

javascript - 在 anchor 中动态设置类不起作用?

html - 在html5中渲染MS Symbol字体字符

javascript - Switch 语句如何与符号一起使用?

windbg - 如何摆脱与符号文件相关的警告/错误消息