在Google中搜索符号非常困难,所以我在此问这里.
<! - 看起来像是对我的评论,但它不像html那样工作.或者它就像//一行注释? 使用它的目的和好处是什么?谢谢 示例代码:
<script type="text/javascript">
<!--
alert("example");
//-->
</script>
最佳答案:
这是一种从浏览器中隐藏JavaScript的旧方法,它将脚本元素的文本节点视为普通文本(并显示您的代码).
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.