【发布时间】:2018-09-29 13:21:44
【问题描述】:
所以我有这份文件:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(document).ready(function() {
//executes when HTML-Document is loaded and DOM is ready
alert("document is ready");
});
$(window).on("load", function () {
//executes when HTML-Document is loaded and DOM is ready
alert("window is loaded");
});
</script>
</body>
</html>
注意 2 个函数调用中的内联 cmets。
显然这些不起作用并给我一个错误:
SyntaxError: missing } after function body[Weitere Informationen] index:1:297 note: { opened at line 1, column 37
但是,使用多行注释 /* */ 效果很好。
我假设,单行 cmets 不起作用,因为 javascript 以某种方式被缩小为一行。
有人可以评估这是如何发生的吗?
哪里可以使用单行 cmets,哪里不能?
还是在 js 中使用单行 cmets 通常是个坏主意?
【问题讨论】:
-
您是自己缩小它,还是使用外部工具?
-
@ibrahimmahrir im 使用 phalcon php 框架作为 MVC。如果我只是加载一个普通的 html 文件,则不会发生此行为。也许这是使用 phalcon 使用 {{ }} 表示法呈现不同视图的错误。我自己并没有明确地缩小任何东西。(但我的框架做了类似的事情-.-)
-
@ibrahimmahrir 感谢您的重播。实际上是 phalcon 框架缩小了文档:
标签: javascript function comments inline