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とFF3.5で表示されます。何かご意見は?

4

2 に答える 2

3

あなたはdocument.close()後をしなければなりませんdocument.writeln()

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

参照:この質問も。

于 2009-12-02T16:24:19.930 に答える
1

編集:この投稿が役立つかどうかを確認してください。私はクロムを使用していません、そしてあなたは追加しなければなりませんdocument.close();

;document.writeln("x = " + x)(?)にありません

于 2009-12-02T16:19:28.830 に答える