为什么我的javascript会被评论

Why does my javascript get commented

本文关键字:评论 javascript 我的 为什么      更新时间:2023-09-26

所以我正在研究这个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)在我的脚本周围放置评论吗?脚本似乎可以正常工作...

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

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