新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)JAVAscript和HTMLDOM參考手冊:HTMLDOM屬性對象
HTML DOM 節(jié)點
在 HTML DOM (Document Object Model) 中, 所有的都是 節(jié)點:

- 文檔是文檔節(jié)點
- 所有 HTML 元素是元素節(jié)點
- 所有 HTML 屬性都是屬性節(jié)點
- 插入到 HTML 元素中的文本為文本節(jié)點
- 注釋是注釋節(jié)點
Attr 對象
在 HTML DOM 中, Attr 對象 代表一個 HTML 屬性。
HTML屬性總是屬于HTML元素。
NamedNodeMap 對象
在 HTML DOM 中, the NamedNodeMap 對象 表示一個無順序的節(jié)點列表。
我們可通過節(jié)點名稱來訪問 NamedNodeMap 中的節(jié)點。
瀏覽器支持
所有主流瀏覽器都支持 Attr 對象和 NamedNodeMap 對象。
| 屬性 / 方法 | 描述 |
|---|---|
| attr.isId | 如果屬性是 ID 類型,則 isId 屬性返回 true,否則返回 false。 |
| attr.name | 返回屬性名稱 |
| attr.value | 設(shè)置或者返回屬性值 |
| attr.specified | 如果屬性被指定返回 true,否則返回 false |
| nodemap.getNamedItem() | 從節(jié)點列表中返回的指定屬性節(jié)點。 |
| nodemap.item() | 返回節(jié)點列表中處于指定索引號的節(jié)點。 |
| nodemap.length | 返回節(jié)點列表的節(jié)點數(shù)目。 |
| nodemap.removeNamedItem() | 刪除指定屬性節(jié)點 |
| nodemap.setNamedItem() | 設(shè)置指定屬性節(jié)點(通過名稱) |
DOM 4 警告 !!!
在 W3C DOM 內(nèi)核中, Attr (屬性) 對象繼承節(jié)點對象的所有屬性和方法 。
在 DOM 4 中, Attr (屬性) 對象不再從節(jié)點對象中繼承。
從長遠的代碼質(zhì)量來考慮,在屬性對象中你需要避免使用節(jié)點對象屬性和方法:
| 屬性 / 方法 | 避免原因 |
|---|---|
| attr.appendChild() | 屬性沒有子節(jié)點 |
| attr.attributes | 屬性沒有屬性 |
| attr.baseURI | 使用 document.baseURI 替代 |
| attr.childNodes | 屬性沒有子節(jié)點 |
| attr.cloneNode() | 使用 attr.value 替代 |
| attr.firstChild | 屬性沒有子節(jié)點 |
| attr.hasAttributes() | 屬性沒有屬性 |
| attr.hasChildNodes | 屬性沒有子節(jié)點 |
| attr.insertBefore() | 屬性沒有子節(jié)點 |
| attr.isEqualNode() | 沒有意義 |
| attr.isSameNode() | 沒有意義 |
| attr.isSupported() | 通常為 true |
| attr.lastChild | 屬性沒有子節(jié)點 |
| attr.nextSibling | 屬性沒有兄弟節(jié)點 |
| attr.nodeName | 使用 attr.name 替代 |
| attr.nodeType | 通常為 2 (ATTRIBUTE-NODE) |
| attr.nodeValue | 使用 attr.value 替代 |
| attr.normalize() | 屬性沒有規(guī)范 |
| attr.ownerDocument | 通常為你的 HTML 文檔 |
| attr.ownerElement | 你用來訪問屬性的 HTML 元素 |
| attr.parentNode | 你用來訪問屬性的 HTML 元素 |
| attr.previousSibling | 屬性沒有兄弟節(jié)點 |
| attr.removeChild | 屬性沒有子節(jié)點 |
| attr.replaceChild | 屬性沒有子節(jié)點 |
| attr.textContent | 使用 attr.value 替代 |
本文標題:創(chuàng)新互聯(lián)JAVAscript和HTMLDOM參考手冊:HTMLDOM屬性對象
本文URL:http://fisionsoft.com.cn/article/djgjjgc.html


咨詢
建站咨詢
