| 名稱 | 型態 | 描述 |
|---|---|---|
| document.activeElement | Element | 回傳目前聚焦的元素物件 |
| document.alinkColor | String | 設定 <a> 元素在滑鼠點擊瞬間顏色 |
| document.anchors | HTMLCollection | 所有連結所集合成的物件 |
| document.bgColor | String | 設定文件背景的顏色 |
| document.cookie | String | 設定 Cookie 資料 |
| document.documentElement | Element | 取得根元素的物件 |
| document.documentURI | String | 回傳文件中目前的網址 |
| document.forms | HTMLCollection | 回傳文件中所有表單集合成的物件 |
| document.images | HTMLCollection | 回傳文件中所有圖片集合成的物件 |
| document.inputEncoding | String | 回傳文件的編碼格式 |
| document.lastModified | String | 回傳文件最後修改的時間 |
| document.lastStyleSheetSet | String | 回傳文件最後的樣式表 |
| document.linkColor | String | 回傳連結 <a> 元素的文字顏色 |
| document.links | HTMLCollection | 回傳文件中所有連結所集合成的物件 |
| document.location | Location | 回傳文件的 location 物件 |
| document.plugins | HTMLCollection | 回傳文件中所有 <embed> 元素所集合成的物件 |
| document.preferredStyleSheetSet | String | 回傳文件作者的樣式表 |
| document.readyState | String | 回傳文件目前的狀態 |
| document.referrer | String | 回傳連結到文件的 URI |
| document.selectedStyleSheetSet | String | 回傳文件選擇的樣式表 |
| document.styleSheets | HTMLCollection | 回傳文件樣式表所集合成的物件 |
| document.styleSheetSets | HTMLCollection | 回傳文件樣式表所集合成的物件 |
| document.title | String | 回傳文件的標題 |
| document.URL | String | 回傳文件的網址 |
| document.vlinkColor | String | 回傳連結 <a> 元素拜訪過的顏色 |
| 名稱 | 描述 |
|---|---|
| document.close() | 關閉輸入串流 |
| document.createAttribute(name_str) | 替元素物件新增屬性 |
| document.createElement(element_str) | 替文件物件新增元素 |
| document.createTextNode(text_str) | 替文件物件新增文字節點 |
| document.enableStyleSheetsForSet(ss_str) | 設定文件物件的樣式表 |
| document.getElementById(id_str) | 回傳 id 屬性的元素物件 |
| document.getElementsByClassName(cn_str) | 回傳 class 屬性的集合物件 |
| document.getElementsByName(n_str) | 回傳 name 屬性的集合物件 |
| document.getElementsByTagName(tn_str) | 回傳元素標籤的集合物件 |
| document.hasFocus() | 判斷本文件是否為目前視窗的焦點 |
| document.open() | 開啟輸入串流 |
| document.write(str) | 以不主動分行的方式,將字串寫入網頁 |
| document.writeln(str) | 以主動分行的方式,將字串寫入網頁 |
舉例如下
function run() {
var c = randomColor();
document.bgColor = c;
}
function randomColor() {
var c1 = (Math.random() * 1000) % 256;
var c2 = (Math.random() * 1000) % 256;
var c3 = (Math.random() * 1000) % 256;
c1 = hex(Math.floor(c1));
c2 = hex(Math.floor(c2));
c3 = hex(Math.floor(c3));
return "#" + c1 + c2 + c3;
}
function hex(n) {
var result = "";
var temp, count;
while (n > 16) {
count = 1;
while (n > exp(16, count)) {
count += 1;
}
count -= 1;
temp = n / exp(16, count);
temp = Math.floor(temp);
result += hexLetter(temp);
n -= exp(16, count) * temp;
}
if (n == 16) {
result += "1";
n -= 16;
}
result += hexLetter(n);
return result;
}
function hexLetter(n) {
if (n >= 16 || n < 0) {
return "";
}
else {
switch (n) {
case 10:
return "A";
case 11:
return "B";
case 12:
return "C";
case 13:
return "D";
case 14:
return "E";
case 15:
return "F";
default:
return "" + n;
}
}
}
function exp(x, y) {
var result = 1;
while (y > 0) {
result *= x;
y -= 1;
}
return result;
}
/* 《程式語言教學誌》的範例程式
http://pydoing.blogspot.com/
檔名:document005.js
功能:示範 JavaScript 程式
作者:張凱慶
時間:西元 2011 年 8 月 */此例是藉由 randomColor() 函數 (function) 產生隨機的顏色,然後在 run() 中
document.bgColor = c;
將顏色指派給 document.bgColor ,文件背景顏色就會變換成所產生的隨機顏色。
我們以下面的 HTML 文件載入
<!DOCTYPE html>
<html>
<head>
<title>HTML DOM DEMO</title>
<script src="document005.js" type="text/javascript"></script>
</head>
<body>
<input type="button" value="RUN" onclick="run();">
</body>
</html>
<!-- 《程式語言教學誌》的範例程式
http://pydoing.blogspot.com/
檔名:document005.html
功能:示範 JavaScript 程式
作者:張凱慶
時間:西元 2011 年 8 月 -->瀏覽器 (broswer) 開啟,按下 RUN 就會改變背景顏色

| 中英文術語對照 | |
|---|---|
| 屬性 | attribute |
| 方法 | method |
| 函數 | function |
| 瀏覽器 | 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
http://www.w3.org/TR/DOM-Level-3-Core/core.html#i-Document
沒有留言:
張貼留言