HTML DOM close() 方法
定義和用法
close() 方法可關(guān)閉一個(gè)由 document.open 方法打開(kāi)的輸出流,并顯示選定的數(shù)據(jù)。
語(yǔ)法
document.close()
說(shuō)明
該方法將關(guān)閉 open() 方法打開(kāi)的文檔流,并強(qiáng)制地顯示出所有緩存的輸出內(nèi)容。如果您使用 write() 方法動(dòng)態(tài)地輸出一個(gè)文檔,必須記住當(dāng)你這么做的時(shí)候要調(diào)用 close() 方法,以確保所有文檔內(nèi)容都能顯示。
一旦調(diào)用了 close(),就不應(yīng)該再次調(diào)用 write(),因?yàn)檫@會(huì)隱式地調(diào)用 open() 來(lái)擦除當(dāng)前文檔并開(kāi)始一個(gè)新的文檔。
實(shí)例
<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>