Javascript:window.onload 问题

发布于 2024-08-30 21:58:21 字数 456 浏览 5 评论 0原文

这在 IE 中不起作用(尽管它在 FFX 中起作用)。为什么?

在标题中使用 HTML:

<script type="application/javascript">

    // And finally, let's call the code ourselves.
    window.onload = lbp.init;

</script>

然后是脚本:

// lbp is the script's universal variable, which retains everything
var lbp = {};

// The sequence of functions to trigger
lbp.init = function() {
    alert('hi');
}

提前感谢您的帮助 =)

This isn't working in IE (although it does work in FFX). Why?

Using HTML in the header:

<script type="application/javascript">

    // And finally, let's call the code ourselves.
    window.onload = lbp.init;

</script>

And then the script:

// lbp is the script's universal variable, which retains everything
var lbp = {};

// The sequence of functions to trigger
lbp.init = function() {
    alert('hi');
}

Thanks in advance for your help =)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

差↓一点笑了 2024-09-06 21:58:21

我不知道IE是否支持application/javascript。您尝试过text/javascript吗?

另外:lbp在设置window.onload之前是否已初始化?

I don't know if IE supports application/javascript. Did you try text/javascript?

Also: is lbp initialized before setting window.onload?

瞳孔里扚悲伤 2024-09-06 21:58:21

IE 不支持除 PDF 之外的应用程序 MIME 类型。这意味着 IE 将完全忽略你的 JavaScript。将其更改为 mime 类型 text/javascript

IE does not support application mime types except for with PDFs. This means IE will completely ignore your JavaScript. Change it to mime type text/javascript.

梦里泪两行 2024-09-06 21:58:21

我认为您在 window.onload = lbp.init; 代码之后声明了 lbp 。由于序列问题,您的代码无法运行。

请按以下顺序尝试代码。

<script type="text/javascript" language="javascript">
    var lbp = {};
        // The sequence of functions to trigger
        lbp.init = function() {
        alert('hi');
    }
        
    // And finally, let's call the code ourselves.
    window.onload = lbp.init;
</script>

I think you have declared lbp after window.onload = lbp.init; code. Your code is not working because of the sequence issue.

Try the code in the following sequence.

<script type="text/javascript" language="javascript">
    var lbp = {};
        // The sequence of functions to trigger
        lbp.init = function() {
        alert('hi');
    }
        
    // And finally, let's call the code ourselves.
    window.onload = lbp.init;
</script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文