javascript 包含函数 window.onload

发布于 2024-08-23 00:54:30 字数 445 浏览 3 评论 0原文

我在一个单独的页面上有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烂人 2024-08-30 00:54:30

这就是你所拥有的吗?这实际上有效:

function func1(){
    alert('Works');
}

window.onload = func1;

Is this what you have? This actually works:

function func1(){
    alert('Works');
}

window.onload = func1;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文