javascript DOM æä½åºç¡ç¥è¯å°ç»_javascriptæå·§
程序员文章站
2022-06-01 18:49:10
...
DOMæ·»å å
ç´ ,使ç????ç¹å??æ??
[Ctrl+A å ???? æ³??:å¦??å¼å ¥å??????Js??å·æ??æ??½æ?쨨¡]
ä¸ãDOMåºç¡
1.??ç¹(node)å??次
Documentï¼ï¼æ??¡¶å??ç??ç¹ï¼ææçå ¶ä»??ç¹??½æ¯??å??äºå®çã
DocumentTypeï¼ï¼DTDå¼ç??ï¼ä½¿ç????¯æ³ï¼ç对????¡??¡??ç??å½¢å¼ï¼å®ä¸??½å å«å??ç¹ã
DocumentFragmentï¼ï¼å¯ä»¥åDocumentä¸æ ·æ¥ä¿åå ¶ä»??ç¹ã
Elementï¼ï¼??¡??ç??º??µ·å??æ ç¾åç»ææ ç¾ä¹??´çå 容ï¼ä¾å¦æ??
ã??¿æ¯å¯ä¸å¯ä»¥åæ¶å
å«ç¹æ??åå??ç¹ç??ç¹ç??»åã
Attrï¼ï¼ä»£??¡??ä¸å¯¹ç¹æ??ååç¹æ??å¼ã??¿ä¸ª??ç¹ç??»åä¸??½å å«å??ç¹ã
Textï¼ï¼ä»£??¡??XMLææ¡£ä¸çå????µ·å??æ ç¾åç»ææ ç¾ä¹??´ï¼æ?? CDataSectionå å å«çæ®??ææ¬ã??¿ä¸ª??ç¹ç??»åä¸??½å å«å??ç¹ã
CDataSectionï¼ï¼ç对????¡??¡??ç??å½¢å¼ã??¿ä¸ª??ç¹ç??»åä» ??½å å«ææ¬??ç¹Textä½ä¸ºå??ç¹ã
Entityï¼ï¼??¡??ç??ºå??DTDä¸çä¸ä¸ªå®ä½å®ä¹ï¼ä¾å¦ã??¿ä¸ª??ç¹ç??»åä¸??½å å«å??ç¹ã
EntityReferenceï¼ï¼ä»£??¡??ä¸ä¸ªå®ä½å¼ç??ï¼ä¾å¦"ã??¿ä¸ª??ç¹ç??»åä¸??½å å«å??ç¹ã
ProcessingInstructionï¼ï¼ä»£??¡??ä¸ä¸ªPIã??¿ä¸ª??ç¹ç??»åä¸??½å å«å??ç¹ã
Commentï¼ï¼ä»£??¡??XMLæ³????ã??¿ä¸ª??ç¹ä¸??½å å«å??ç¹ã
Notationï¼ï¼ä»£??¡??å??DTDä¸å®ä¹ç??®??å·ã??¿ä¸ªå¾å??ç??å??ã
Nodeæ¥å£å®ä¹äºææ??ç¹ç??»å??½å å«çç¹æ??åæ¹æ³ã
???訨ç¹å??ï¼DOM??¿å®ä¹äºä¸äºå©æ对????¡ï¼å®ä»¬å¯ä»¥å??ç¹ä¸??µ·ä½¿ç??ï¼ä½ä¸æ¯DOMææ¡£å¿ æç????åã
NodeListï¼ï¼??ç¹æ??ç»ï¼æç ??æ??å¼??¿??¡ç´¢å¼;ç??æ¥??¡??ç??ºåä¸ä¸ªå ç´ çå??ç¹ã
NamedNodeMapï¼ï¼åæ¶ä½¿ç??æ??å¼ååå??¿??¡ç´¢å¼ç??ç¹??¡??;ç??äº??¡??ç??ºå ç´ ç¹æ??ã
2.??®¿??®ç¸å ³ç??ç¹
ä¸??¢çå ??ä¸????ä¸??¢çHTML??¡µ??¢
DOM Example
??¦??®¿??® å
ç´ ï¼ä½ åº??¯¥æç½??¿æ¯??¯¥æ件çdocumentå
ç´ ï¼ï¼ä½ å¯ä»¥ä½¿ç??documentçdocumentElementç¹æ??ï¼
var oHtml = document.documentElement;
ç??å??å??oHtmlå å«ä¸ä¸ª??¡??ç??º
[Ctrl+A å ???? æ³??:å¦??å¼å ¥å??????Js??å·æ??æ??½æ?쨨¡]
ä¸ãDOMåºç¡
1.??ç¹(node)å??次
Documentï¼ï¼æ??¡¶å??ç??ç¹ï¼ææçå ¶ä»??ç¹??½æ¯??å??äºå®çã
DocumentTypeï¼ï¼DTDå¼ç??ï¼ä½¿ç????¯æ³ï¼ç对????¡??¡??ç??å½¢å¼ï¼å®ä¸??½å å«å??ç¹ã
DocumentFragmentï¼ï¼å¯ä»¥åDocumentä¸æ ·æ¥ä¿åå ¶ä»??ç¹ã
Elementï¼ï¼??¡??ç??º??µ·å??æ ç¾åç»ææ ç¾ä¹??´çå 容ï¼ä¾å¦
Attrï¼ï¼ä»£??¡??ä¸å¯¹ç¹æ??ååç¹æ??å¼ã??¿ä¸ª??ç¹ç??»åä¸??½å å«å??ç¹ã
Textï¼ï¼ä»£??¡??XMLææ¡£ä¸çå????µ·å??æ ç¾åç»ææ ç¾ä¹??´ï¼æ?? CDataSectionå å å«çæ®??ææ¬ã??¿ä¸ª??ç¹ç??»åä¸??½å å«å??ç¹ã
CDataSectionï¼ï¼ç对????¡??¡??ç??å½¢å¼ã??¿ä¸ª??ç¹ç??»åä» ??½å å«ææ¬??ç¹Textä½ä¸ºå??ç¹ã
Entityï¼ï¼??¡??ç??ºå??DTDä¸çä¸ä¸ªå®ä½å®ä¹ï¼ä¾å¦ã??¿ä¸ª??ç¹ç??»åä¸??½å å«å??ç¹ã
EntityReferenceï¼ï¼ä»£??¡??ä¸ä¸ªå®ä½å¼ç??ï¼ä¾å¦"ã??¿ä¸ª??ç¹ç??»åä¸??½å å«å??ç¹ã
ProcessingInstructionï¼ï¼ä»£??¡??ä¸ä¸ªPIã??¿ä¸ª??ç¹ç??»åä¸??½å å«å??ç¹ã
Commentï¼ï¼ä»£??¡??XMLæ³????ã??¿ä¸ª??ç¹ä¸??½å å«å??ç¹ã
Notationï¼ï¼ä»£??¡??å??DTDä¸å®ä¹ç??®??å·ã??¿ä¸ªå¾å??ç??å??ã
Nodeæ¥å£å®ä¹äºææ??ç¹ç??»å??½å å«çç¹æ??åæ¹æ³ã
ç¹æ??/æ¹æ³ | ç??»å/??¿åç??»å | ??¯´æ |
nodeName | String | ??ç¹çåå;æ ¹æ®??ç¹çç??»å??å®ä¹ |
nodeValue | String | ??ç¹çå¼;æ ¹æ®??ç¹çç??»å??å®ä¹ |
nodeType | Number | ??ç¹çç??»å常??å¼ä¹ä¸ |
ownerDocument | Document | æå??¿ä¸ª??ç¹æå??çææ¡£ |
firstChild | Node | æåå??childNodeså??¡??ä¸ç第ä¸ä¸ª??ç¹ |
lastChild | Node | æåå??childNodeså??¡??ä¸çæåä¸ä¸ª??ç¹ |
childNodes | NodeList | ææå??ç¹çå??¡?? |
previousSibling | Node | æååä¸ä¸ªå å¼??ç¹;å¦æ??¿ä¸ª??ç¹å????æ¯ç¬¬ä¸ä¸ªå å¼??ç¹ï¼??£ä¹??¯¥å¼ä¸ºnull |
nextSibling | Node | æååä¸ä¸ªå å¼??ç¹;å¦æ??¿ä¸ª??ç¹å????æ¯æåä¸ä¸ªå å¼??ç¹ï¼??£ä¹??¯¥å¼ä¸ºnull |
hasChildNodes() | Boolean | å½childNodeså å«ä¸ä¸ªæå??个??ç¹æ¶,??¿åç |
attributes | NamedNodeMap | å å«äºä»£??¡??ä¸ä¸ªå ç´ çç¹æ??çAttr对????¡;ä» ç??äºElement??ç¹ |
appendChild(node) | Node | å??nodeæ·»å å??childNodesçæ«å??¾ |
removeChild(node) | Node | ä»childNodesä¸å ????node |
replaceChild(newnode,oldnode) | Node | å??childNodesä¸çoldnodeæ¿æ¢ænewnode |
insertBefore(newnode,refnode) | Node | å??childNodesä¸çrefnodeä¹åæå ¥newnodd |
???訨ç¹å??ï¼DOM??¿å®ä¹äºä¸äºå©æ对????¡ï¼å®ä»¬å¯ä»¥å??ç¹ä¸??µ·ä½¿ç??ï¼ä½ä¸æ¯DOMææ¡£å¿ æç????åã
NodeListï¼ï¼??ç¹æ??ç»ï¼æç ??æ??å¼??¿??¡ç´¢å¼;ç??æ¥??¡??ç??ºåä¸ä¸ªå ç´ çå??ç¹ã
NamedNodeMapï¼ï¼åæ¶ä½¿ç??æ??å¼ååå??¿??¡ç´¢å¼ç??ç¹??¡??;ç??äº??¡??ç??ºå ç´ ç¹æ??ã
2.??®¿??®ç¸å ³ç??ç¹
ä¸??¢çå ??ä¸????ä¸??¢çHTML??¡µ??¢
å??å¶ä»£ç 代ç å¦ä¸:
Hello World!
Isn't this exciting?
You're learning to use the DOM!
??¦??®¿??®
var oHtml = document.documentElement;
ç??å??å??oHtmlå å«ä¸ä¸ª??¡??ç??º
上一篇: 怎么将个位十位百位.分开显示
下一篇: 最常用的SQL语句
推荐阅读
-
JavaScript, 函数是实现异步的基础
-
巧用批处理解决IE不支持JavaScript等问题
-
JavaScript prototype原型用法
-
林大妈的JavaScript基础知识(二):编写JavaScript代码前的一些简单工作
-
Javascript绑定事件的两种方式的区别
-
javascript 鼠标悬浮图片显示原图 移出鼠标后原图消失(多图)
-
JavaScript中:表达式和语句的区别[译]_javascript技巧
-
javascript - 情感分析课题:怎么构建自己的情感词库
-
JS延迟加载(setTimeout) JS最后加载_javascript技巧
-
JS实现求出一个字符串中最多出现的字符和个数_javascript技巧