javascript 包含函数 window.onload
我在一个单独的页面上有 2 个函数,我将其包含在 .html 页面的标题中。在我包含它的部分下,我有以下代码: window.onload = func1;
我想获取这一小段代码,并将其包含在包含的 .js 页面中,该页面具有以下功能它,所以本质上会有这个函数,然后就在 window.onload 的下面。但是当我这样做时,代码不起作用,有什么想法吗?
代码不是问题,如果我这样做:
function alert1() {
alert("hi");
}
window.onload = alert1;
那么它仍然不会显示,因为它位于包含的 .js 页面中
<script type="text/javascript" src="menu.js"></script>
I have 2 functions on a seperate page that I am including of the header of the .html page. Under the part where I include it, I have this code: window.onload = func1;
I want to take that little snippet of code, and include it inside the included .js page which has the function in it, so essentially there will be the function, then right under that the window.onload thing. But when I do this, the code doesnt work, any ideas?
The code isnt the problem, if I do:
function alert1() {
alert("hi");
}
window.onload = alert1;
Then it still doesnt show up because that is in the included .js page
<script type="text/javascript" src="menu.js"></script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这就是你所拥有的吗?这实际上有效:
Is this what you have? This actually works: