0

在 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 中。有什么想法吗?

4

2 回答 2

3

You have to do a document.close() after document.writeln():

            function onBodyLoad()
            {                               
                    var x = 42;
                    document.writeln("x = " + x);
                    alert("on load");
                    document.close();
            }

See: this question as well.

于 2009-12-02T16:24:19.930 回答
1

编辑:检查这篇文章是否有帮助。我不使用 chrome,你必须添加document.close();

;document.writeln("x = " + x)在(?)中失踪

于 2009-12-02T16:19:28.830 回答