简体   繁体   English

html onload没有运行javascript

[英]html onload not running javascript

I'm writing a game in javascript, and I had the world generator running fine, but when I created a startup function to run multiple things at once, my code doesn't run at all anymore. 我正在用javascript编写游戏,并且我的world生成器运行良好,但是当我创建了一个启动功能来一次运行多个功能时,我的代码不再运行了。 Can anyone see my problem? 谁能看到我的问题?

<head>
<title>Project Rust</title>
<!-- <link href="/YOUR_PATH/favicon.ico" rel="icon" type="image/x-icon" /> -->
<script src="Scripts/startup.js"></script>
<script src="Scripts/drawmap.js"></script>
<script src="Scripts/maps.js"></script>
<script src="Scripts/mapread.js"></script>
<script src="Scripts/mainchar.js"></script>
</head>
<body bgcolor="#BFE3FF" onload="startup()">
</body>

startup.js: startup(){ alert("start"); drawmap(Screen[0]); mainchar(); } startup.js: startup(){ alert("start"); drawmap(Screen[0]); mainchar(); } startup(){ alert("start"); drawmap(Screen[0]); mainchar(); }

Try this: 尝试这个:

function startup(){
    alert("start"); drawmap(Screen[0]); mainchar();
}

You should set the type to the script tags: 您应该将类​​型设置为脚本标签:

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

Also, you need to use the function keyword to define a function in javascript: 另外,您需要使用function关键字在javascript中定义函数:

function startup(){
  alert("start");
  drawmap(Screen[0]);
  mainchar();
}

If it's still now working, open your browser's javascript console and you should see the error. 如果现在仍然可以使用,请打开浏览器的JavaScript控制台,然后您应该会看到错误消息。

You are missing the function declaration in your startup.js 您在startup.js中缺少函数声明

You need function startup(){ /*your code*/ } 您需要function startup(){ /*your code*/ }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM