在 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 - <!-- 在 Javascript 中是做什么的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5932585/