[JavaScript HTML DOM]使用document物件,使用方法document.open()及close()

說明:
document.open() 開始一個HTML文檔
document.close() 關閉一個HTML文檔
用法
document.open(MIMEtype,replace)
MIMEtype
Optional. The type of document you are writing to. Default value is "text/html"
replace
Optional. If set, the history entry for the new document inherits
the history entry from the document which opened this document

此範例設計說明:
第一步、使用open,開一個新的HTML文檔
第二步、使用write,寫入資料
第三步、使用close,關閉
程式:
<html>
<head>
<title>[JavaScript-HTML_DOM]使用document物件,使用方法document.open()及close()</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
function create() {
var newHtml = document.open("text/html", "replace");
newHtml.write("<html><body>[JavaScript-HTML_DOM]使用document物件,使用方法document.open()</body></html>");
newHtml.close();
}
</script>
</head>
<body>
<div>
<input type="button" value="新增一個 html網頁" onclick="create()">
</div>
</body>
</html>
圖:

 





參考:
HTML DOM open() Method

 




 






 
















其它文章


arrow
arrow
    創作者介紹
    創作者 PG Levin Li 的頭像
    PG Levin Li

    程式開發學習之路

    PG Levin Li 發表在 痞客邦 留言(0) 人氣()