为什么我的javascript会被评论

时间:2012-08-15 07:50:45

标签: javascript html browser

所以我正在研究这个TinyMCE javascript,它应该是非常直接的,但这是交易。当我查看我的页面来源时,这就是我所看到的

<script type="text/javascript">
<!--
tinyMCE.init({
mode : "exact",
elements : "content",
theme : "advanced",
skin : "o2k7",
skin_variant : "blue",
plugins : "advimage,advlink,contextmenu,fullscreen,inlinepopups,nonbreaking,paste,preview,print,safari,style,table",
theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,fontselect,fontsizeselect,|,forecolor,backcolor",
theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,bullist,numlist,|,undo,redo,|,link,unlink,anchor,image,|,hr,removeformat,visualaid",
theme_advanced_buttons3 : "tablecontrols,|,preview,print,fullscreen,code",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : true,
fullscreen_new_window : true
});
// -->
</script>

有人可以向我解释为什么我的浏览器(FF和IE)会将评论放在我的脚本周围吗?脚本似乎正常工作......

2 个答案:

答案 0 :(得分:3)

HTML注释可以防止旧浏览器将JavaScript显示为文本。旧浏览器会将您的JS代码视为一个长HTML注释。另一方面,新的JavaScript感知浏览器通常会在标记之间解释JS代码(JS代码的第一行和最后一行将被JavaScript解释器视为单行注释)。

答案 1 :(得分:1)

评论块仅适用于HTML。这在Web开发的早期是常见的做法,其中某些浏览器不支持JavaScript,因此代码被注释掉,因此不会打印到屏幕上。