write()方法將文本字符串寫入文檔流。
注意:當(dāng)document.write()寫入文檔流時,在加載的文檔上調(diào)用document.write()會自動調(diào)用document.open(),這會清除文檔(參見下面的“更多示例”)。
document.write(markup)
document.write("<h2>Hello world</h2>");測試看看?/?
所有瀏覽器完全支持write()方法:
Method | ![]() | ![]() | ![]() | ![]() | ![]() |
write() | 是 | 是 | 是 | 是 | 是 |
參數(shù) | 描述 |
---|---|
markup | 包含要寫入文檔的文本的字符串 |
返回值: | 沒有 |
---|---|
DOM版本: | DOM 2級 |
如果在頁面加載后使用document.write()方法,它將覆蓋所有現(xiàn)有內(nèi)容:
document.write("<p>唯一的內(nèi)容。</p>");測試看看?/?
您還可以傳遞逗號分隔的參數(shù):
document.write("First Argument", " Second Argument ", new Date());測試看看?/?
DOM Document open()方法
DOM Document writeln()方法
DOM Document close()方法