HTML DOM close() 方法
定義和用法
close() 方法可關(guān)閉一個由 document.open 方法打開的輸出流,并顯示選定的數(shù)據(jù)。
語法
document.close()
說明
該方法將關(guān)閉 open() 方法打開的文檔流,并強制地顯示出所有緩存的輸出內(nèi)容。如果您使用 write() 方法動態(tài)地輸出一個文檔,必須記住當(dāng)你這么做的時候要調(diào)用 close() 方法,以確保所有文檔內(nèi)容都能顯示。
一旦調(diào)用了 close(),就不應(yīng)該再次調(diào)用 write(),因為這會隱式地調(diào)用 open() 來擦除當(dāng)前文檔并開始一個新的文檔。
實例
<html>
<head>
<script type="text/javascript">
function createNewDoc()
{
var newDoc=document.open("text/html","replace");
var txt="<html><body>Learning about the DOM is FUN!</body></html>";
newDoc.write(txt);
newDoc.close()
;
}
</script>
</head>
<body>
<input type="button" value="Write to a new document"
onclick="createNewDoc()">
</body>
</html>