Comment 對象表示文檔中注釋節(jié)點的內(nèi)容。
XML DOM - Comment 對象
實例
在下面的例子中,我們會使用 XML 文件 books_comment.xml,以及 JavaScript 函數(shù) loadXMLDoc()。
- createComment() - 創(chuàng)建一個注釋節(jié)點
Comment 對象
Comment 對象表示文檔中注釋節(jié)點的內(nèi)容。
Comment 節(jié)點表示 HTML 或 XML 文檔中的注釋。
使用由 CharacterData 接口繼承的 data 屬性,或使用由 Node 接口繼承的 nodeValue 屬性,可以訪問注釋的內(nèi)容。(即 <!-- 和 --> 之間的文本)。使用由 CharacterData 接口繼承的各種方法可以操作注釋的內(nèi)容。
使用 Document.createComment() 來創(chuàng)建一個注釋對象。
Comment 對象屬性
屬性 | 描述 | IE | F | O | W3C |
---|---|---|---|---|---|
data | 可設(shè)置或返回此節(jié)點的文本。 | 6 | 1 | 9 | Yes |
length | 可返回此節(jié)點的文本的長度。 | 6 | 1 | 9 | Yes |
Comment 對象方法
方法 | 描述 | IE | F | O | W3C |
---|---|---|---|---|---|
appendData() | 向節(jié)點追加數(shù)據(jù)。 | 6 | 1 | 9 | Yes |
deleteData() | 從節(jié)點刪除數(shù)據(jù)。 | 6 | 1 | 9 | Yes |
insertData() | 向節(jié)點中插入數(shù)據(jù)。 | 6 | 1 | 9 | Yes |
replaceData() | 替換節(jié)點中的數(shù)據(jù)。 | 6 | 1 | 9 | Yes |
substringData() | 從節(jié)點中提取數(shù)據(jù)。 | 6 | 1 | 9 | Yes |
相關(guān)頁面
XML DOM 參考手冊:CharacterData 對象