Javascript 加载不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17274601/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Javascript onload not working
提问by Kipt Scriddy
I am using an external javascript file, which I am using to store all my javascript functions in. Next I am trying to call a function from the body, using the next line of code:
我正在使用一个外部 javascript 文件,我用它来存储我所有的 javascript 函数。接下来,我尝试使用下一行代码从主体调用一个函数:
<body onload="imageRefreshBig()">
The only thing that this function does is making an alert box pop up, well that's what's it supposed to do. I know this is a rather easy question but I have been banging my head against a wall trying to find a problem/fix for this issue and nothing is working.
这个函数唯一能做的就是弹出一个警告框,这就是它应该做的。我知道这是一个相当简单的问题,但我一直在努力寻找这个问题的问题/修复方法,但没有任何效果。
I also include the javascript file in my head:
我还在我的脑海中包含了 javascript 文件:
<script type="text/javascript" src="javascript.js"></script>
But as you probably see this isn't working. Could anyone explain what is going wrong with my syntax/thinking. The only thing I could think of is that either my document is not being loaded properly or that I have a syntax error.
但正如您可能看到的那样,这是行不通的。谁能解释我的语法/思维出了什么问题。我唯一能想到的是我的文档没有被正确加载或者我有一个语法错误。
回答by Wilker Iceri
You can try use in javascript:
您可以尝试在 javascript 中使用:
window.onload = function() {
alert("let's go!");
}
Its a good practice separate javascript of html
将 html 的 javascript 分开是一个很好的做法
回答by ?ukasz D?bek
Try this one:
试试这个:
<body onload="imageRefreshBig();">
Also you might want to check Javascript console for errors (in Chrome it's under Shift+ Ctrl+ J).
此外,您可能想检查 Javascript 控制台是否有错误(在 Chrome 中,它位于Shift+ Ctrl+ 下J)。
回答by Shumail
There's nothing wrong with include file in head. It seems you forgot to add;
. Please try this one:
头部包含文件没有任何问题。好像忘记加了;
。请试试这个:
<body onload="imageRefreshBig();">
<body onload="imageRefreshBig();">
But as per my knowledge semicolons are optional. You can try with ;
but better debug code and see if chrome console gives any error.
但据我所知,分号是可选的。您可以尝试使用;
更好的调试代码,看看 chrome 控制台是否给出任何错误。
I hope this helps.
我希望这有帮助。
回答by mohkhan
You are missing the ()
你错过了 ()
<body onload="imageRefreshBig();">