我的页面很基础
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
</head>
<body>
<h1>Title</h1>
<canvas id="can"></canvas>
<video autoplay id="vid" style="cursor:pointer"></video><br>
<script type="application/javascript;version=1.7" src="8bit.js"></script>
</body>
</html>
它加载 JavaScript Firefox,但不加载 Chrome。
如果我将 JavaScript 文件的内容复制并粘贴到 Chrome 的控制台中,那么它运行正常。
为什么它不从 Chrome 中的脚本标签加载?
来自 MDN 的精华关于 let
关键词:
The keyword let
is supported in Chrome only for testing purposes only in the Console and not in the normal flow. Chrome doesn't support let
but Firefox does.
替换以下内容:
<script type="application/javascript;version=1.7" src="8bit.js"></script>
与:
<script type="text/javascript" src="8bit.js"></script>
Chrome 对 type
做出严格的决定属性。所以请小心使用。仅适用于 Firefox,这是有效的:
Only available to code blocks in HTML wrapped in a <script type="application/javascript;version=1.7">
block (or higher version). Beware, however, that as this is a non-standard feature, this will most likely break support for other browsers. XUL script tags have access to these features without needing this special block.
Chrome 的解决方法:
要启用这些特殊关键字,请在脚本 block 顶部添加以下代码:
"use strict";