JavaScript document write String content writes nothing o
阿新 • • 發佈:2018-11-07
分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!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>