我的外部javascript没有执行

My external javascript is not executed

本文关键字:执行 javascript 外部 我的      更新时间:2024-05-24

我试图在外部javascript中覆盖window.onload事件,但即使在window.load函数之外放置一些基本的console.log行,代码似乎也永远不会执行。

跳转到此处的代码是:
对于index.html:

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Canvas Experimentation</title>
    <script src="canvasEntry3D.js" type="type/javascript"></script>
</head>
<body>
    <canvas id="canvas" height="720" width="1280"></canvas>
</body>
</html>

对于canvasEntry3D.js:

console.log("slkdfnsdnflknegs");
window.onload = abcdefg;
function abcdefg() {
     console.log("in start");
     var canvas = document.getElementById("canvas");
}

为了真正知道浏览器是否加载了正确的javascript文件,我已经检查了developer控制台。

并且我没有搜索覆盖两次window.onlad事件,因此不需要使用addEventListeners(也没有其他javascript代码覆盖window.onload事件)

我看到的代码中唯一的错误是脚本标记中的错误类型属性。

只需从中更改即可

<script src="canvasEntry3D.js" type="type/javascript"></script>

<script src="canvasEntry3D.js" type="text/javascript"></script>