在 Google Chrome 中,在 body onload 上写入 DOM 不起作用
在Google Chrome中,下面的代码片段:
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<title>Example</title>
<script type = "text/javascript">
<!--
function onBodyLoad()
{
var x = 42;
document.writeln("x = " + x);
alert("on load");
}
-->
</script>
</head>
<body onload = "onBodyLoad()"></body>
</html>
不是写
x = 42
到文档中。但是会显示警报。文本和警报均在 IE8 和 FF 3.5 中显示。有什么想法吗?
In Google Chrome, the following code snippet:
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<title>Example</title>
<script type = "text/javascript">
<!--
function onBodyLoad()
{
var x = 42;
document.writeln("x = " + x);
alert("on load");
}
-->
</script>
</head>
<body onload = "onBodyLoad()"></body>
</html>
Is not writing
x = 42
to the document. The alert however is displayed. The text and the alert are both displayed in IE8 and FF 3.5. Any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须在
document.writeln()
之后执行document.close()
:请参阅:这个问题也是如此。
You have to do a
document.close()
afterdocument.writeln()
:See: this question as well.
编辑:检查并查看此帖子 有帮助。我不使用 chrome,你必须添加
document.close();
;
中缺少document.writeln("x = " + x)
(?)Edit: Check and see if this post helps. I dont use chrome and you have to add
document.close();
;
missing indocument.writeln("x = " + x)
(?)