1. 程式人生 > >JavaScript document write String content writes nothing o

JavaScript document write String content writes nothing o

分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow

也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!

               

The following html will output nothing on html page, you may meet it before.

<html><head
>
    <title>Tmp HTML</title>    <script type="text/javascript">        document.write(String.fromCharCode(0x204A));    </script></head><body></body></html>

Why nothing displayed? It is because bothdocument.write

and document.writeln method output text into anunready (open) document. That is to say, when the page finishes loading, the document becomesclosed. An attempt to document.write in it will cause the contents to be erased.

You can work around as following:

<html><head>    <title
>
Tmp HTML</title>    <script type="text/javascript">        function MyDocumentWrite() {            document.write(String.fromCharCode(0x204A));        }        window.onload = MyDocumentWrite;    </script></head><body></body></html>
           

給我老師的人工智慧教程打call!http://blog.csdn.net/jiangjunshow

這裡寫圖片描述