Javascript:window.onload 问题
这在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不知道IE是否支持
application/javascript
。您尝试过text/javascript
吗?另外:
lbp
在设置window.onload
之前是否已初始化?I don't know if IE supports
application/javascript
. Did you trytext/javascript
?Also: is
lbp
initialized before settingwindow.onload
?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
.我认为您在
window.onload = lbp.init;
代码之后声明了lbp
。由于序列问题,您的代码无法运行。请按以下顺序尝试代码。
I think you have declared
lbp
afterwindow.onload = lbp.init;
code. Your code is not working because of the sequence issue.Try the code in the following sequence.