舉例如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | <!DOCTYPE html> < html > < head > < title >HTML DOM DEMO</ title > </ head > < body > < pre > < script > document.write("There"); document.write("is"); document.write("no"); document.write("spoon"); document.write("."); document.close(); </ script > </ pre > </ body > </ html > <!-- 《程式語言教學誌》的範例程式 檔名:document047.html 功能:示範 JavaScript 程式 作者:張凱慶 時間:西元 2011 年 8 月 --> |
此例的 JavaScript 程式從第 9 行到第 14 行
9 10 11 12 13 14 | document.write( "There" ); document.write( "is" ); document.write( "no" ); document.write( "spoon" ); document.write( "." ); document.close(); |
這裡共呼叫 write() 五次,每一次都以沒有空格區分的英文單字與句點當參數 (parameter) 。
瀏覽器 (broswer) 開啟,結果如下

結果顯而易見,所有的單字都擠在一起。
如果使用 write() 要有分行的效果,參數中就需要加入 <br> 或 <p> 之類的區塊標籤。
中英文術語對照 | |
---|---|
方法 | method |
字串 | string |
參數 | parameter |
瀏覽器 | broswer |
您可以繼續參考
基本概念
文件物件 document
- 屬性
- document.activeElement
- document.alinkColor
- document.anchors
- document.bgColor
- document.cookie
- document.documentElement
- document.documentURI
- document.forms
- document.images
- document.inputEncoding
- document.lastModified
- document.lastStyleSheetSet
- document.linkColor
- document.links
- document.location
- document.plugins
- document.preferredStyleSheetSet
- document.readyState
- document.referrer
- document.selectedStyleSheetSet
- document.styleSheets
- document.styleSheetSets
- document.title
- document.URL
- document.vlinkColor
- 方法
- document.close()
- document.createAttribute(name_str)
- document.createElement(element_str)
- document.createTextNode(text_str)
- document.enableStyleSheetsForSet(ss_str)
- document.getElementById(id_str)
- document.getElementsByClassName(cn_str)
- document.getElementsByName(n_str)
- document.getElementsByTagName(tn_str)
- document.hasFocus()
- document.open()
- document.write(str)
- document.writeln(str)
相關目錄
HTML DOM 快速導覽
JavaScript 教材
首頁
參考資料
https://developer.mozilla.org/en/DOM/document.write
http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-75233634
沒有留言:
張貼留言