我正在从雄辩的JavaScript中完成“创建平台游戏”项目,并且有一个脚本标记的问题。
在这本书中,我们被告知要使用以下方法来显示我们的级别:
<link rel="stylesheet" href="css/game.css">
<script>
var simpleLevel = new Level(simpleLevelPlan);
var display = new DOMDisplay(document.body, simpleLevel);
</script>我尝试将这个(以及我的platform.js文件的附加脚本标记)添加到index.html中,但是浏览器没有返回任何内容,不确定我做错了什么?
发布于 2016-09-12 08:48:34
确保以正确的顺序插入脚本:
<!DOCTYPE html>
<html>
<head>
Here you should put your "included" scripts with <script src=...>
</head>
<body>
...
</body>
<script>
Here you should put your first execution, if it needs the html page been completely loaded (as to use document.body).
</script>
</html>当脚本出现在页面中时,脚本将被执行。如果使用document,则必须将执行推迟到加载完整个页面:要么将脚本放在HTML的末尾,要么将初始化函数放在头部,然后从body onload调用它:
<head>
<script>
function myFunction(){...}
</script>
</head>
<body onload="return myFunction()">
...
</body>发布于 2016-09-12 08:26:31
确保在内联脚本之前将所需的外部JavaScript文件包含在单独的<script>标记中!
https://stackoverflow.com/questions/39444301
复制相似问题