快速业务通道

Javascript文档对象模型(DOM)实例分析

作者 佚名技术 来源 网页制作 浏览 发布时间 2012-03-07
h;———————————

DOM的核心: Node

由于DOM是树形结构,所以一个节点被抽象为对象Node,这是DOM的核心对象:

Node的种类一共有12种,通过Node.nodeType的取值来确定(为1-12),分为:

❑ Node.ELEMENT_NODE (1)

❑ Node.ATTRIBUTE_NODE (2)

❑ Node.TEXT_NODE (3) :<![CDATA[ ]]>中括着的纯文本,他没有子节点

❑ Node.CDATA_SECTION_NODE (4) :子节点一定为TextNode

❑ Node.ENTITY_REFERENCE_NODE (5) :

❑ Node.ENTITY_NODE (6) :DTD中的实体定义<!ENTITY foo “foo”>,无子节点

❑ Node.PROCESSING_INSTRUCTION_NODE (7) :PI,无子节点

❑ Node.COMMENT_NODE (8)

❑ Node.DOCUMENT_NODE (9) :最外层的Root element,包括所有其它节点

❑ Node.DOCUMENT_TYPE_NODE (10) :DTD,<!DOCTYPE………..>

❑ Node.DOCUMENT_FRAGMENT_NODE (11)

❑ Node.NOTATION_NODE (12) :DTD中的Nation定义

Node的属性和方法

nodeName 返回String. The name of ths node;this is defined depending on theype of node.
nodeValue 返回String. The value of the node''this is defined depending on the type of node.
nodeType 返回Number. One of the node type constant values.
ownerDocument 返回Document. Pointer to the document that this node belongs to.
firstChild 返回Node. Pointer to the first node in the childNodes list.
lastChild 返回Node. Pointer to the last node in the childNodes list.
childNodes 返回NodeList. A list of all child nodes.
previousSibling 返回Node. Pointer to the previous sibling;null if this is the first sibling.
nextSibling 返回Node. Pointer to the next sibling;null if this is the last sibling.
attributes 返回NamedNodeMap. Contains Attr objects respresenting an element''s attributes;only used for Element nodes.
appendChild(node) 返回Node. Adds node to the end of childNodes.
hasChildNodes() 返回Boolean. Returns true when childNodes contains one or more nodes.
removeChild(node) 返回Node. Removes node from childNodes.
replaceChild(newnode, oldnode) 返回Node. Replace oldnode in

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号