龙空技术网

重学前端基础:如何查看文档对象的所有属性?如何文档查找节点?

代码开发 119

前言:

目前你们对“html中alignitems”可能比较关心,你们都需要剖析一些“html中alignitems”的相关资讯。那么小编在网上收集了一些有关“html中alignitems””的相关内容,希望同学们能喜欢,各位老铁们一起来了解一下吧!

文档树

Document Object Model (DOM) 为文档对象模型, 它使用对象的表示方式来表示对应的文档结构及其中的内容。

下面为一个样例 p 元素在文档中的对象所包含的所有属性。

控制台:

p#domaccessKey: ""align: ""assignedSlot: nullattributeStyleMap: StylePropertyMap {size: 0}attributes: NamedNodeMap {0: id, id: id, length: 1}autocapitalize: ""baseURI: ""childElementCount: 0childNodes: NodeList [text]children: HTMLCollection []classList: DOMTokenList [value: ""]className: ""clientHeight: 26clientLeft: 0clientTop: 0clientWidth: 713contentEditable: "inherit"dataset: DOMStringMap {}dir: ""draggable: falsefirstChild: textfirstElementChild: nullhidden: falseid: "dom"innerHTML: "查看我自己都有哪些属性"innerText: "查看我自己都有哪些属性"inputMode: ""isConnected: trueisContentEditable: falselang: ""lastChild: textlastElementChild: nulllocalName: "p"namespaceURI: ""nextElementSibling: scriptnextSibling: textnodeName: "P"nodeType: 1nodeValue: nullnonce: ""offsetHeight: 26offsetLeft: 8offsetParent: bodyoffsetTop: 20offsetWidth: 713onabort: nullonauxclick: nullonbeforecopy: nullonbeforecut: nullonbeforepaste: nullonblur: nulloncancel: nulloncanplay: nulloncanplaythrough: nullonchange: nullonclick: nullonclose: nulloncontextmenu: nulloncopy: nulloncuechange: nulloncut: nullondblclick: nullondrag: nullondragend: nullondragenter: nullondragleave: nullondragover: nullondragstart: nullondrop: nullondurationchange: nullonemptied: nullonended: nullonerror: nullonfocus: nullonfullscreenchange: nullonfullscreenerror: nullongotpointercapture: nulloninput: nulloninvalid: nullonkeydown: nullonkeypress: nullonkeyup: nullonload: nullonloadeddata: nullonloadedmetadata: nullonloadstart: nullonlostpointercapture: nullonmousedown: nullonmouseenter: nullonmouseleave: nullonmousemove: nullonmouseout: nullonmouseover: nullonmouseup: nullonmousewheel: nullonpaste: nullonpause: nullonplay: nullonplaying: nullonpointercancel: nullonpointerdown: nullonpointerenter: nullonpointerleave: nullonpointermove: nullonpointerout: nullonpointerover: nullonpointerup: nullonprogress: nullonratechange: nullonreset: nullonresize: nullonscroll: nullonsearch: nullonseeked: nullonseeking: nullonselect: nullonselectionchange: nullonselectstart: nullonstalled: nullonsubmit: nullonsuspend: nullontimeupdate: nullontoggle: nullonvolumechange: nullonwaiting: nullonwebkitfullscreenchange: nullonwebkitfullscreenerror: nullonwheel: nullouterHTML: "<p id="dom">查看我自己都有哪些属性</p>"outerText: "查看我自己都有哪些属性"ownerDocument: documentparentElement: bodyparentNode: bodyprefix: nullpreviousElementSibling: nullpreviousSibling: textscrollHeight: 26scrollLeft: 0scrollTop: 0scrollWidth: 713shadowRoot: nullslot: ""spellcheck: truestyle: CSSStyleDeclaration {alignContent: "", alignItems: "", alignSelf: "", alignmentBaseline: "", all: "", …}tabIndex: -1tagName: "P"textContent: "查看我自己都有哪些属性"title: ""translate: true__proto__: HTMLParagraphElement

通过使用 DOM 提供的 API (Application Program Interface) 可以动态的修改节点(node),也就是对 DOM 树的直接操作。 浏览器中通过使用 JavaScript 来实现对于 DOM 树的改动。

DOM 包含

DOM Core DOM HTMLDOM StyleDOM EventHTML 转换 DOM 树

<!DOCTYPE html><html lang="en"> <head> <title>My title</title> </head> <body> <a href="">My Link</a> <h1>My header</h1> </body></html>

节点遍历

在元素节点中提取自己所需的节点,并予以操作。

节点类型

常用节点类型

ELEMENT_NODE 可使用 Document.createElement('elementName'); 创建TEXT_NODE 可使用 Document.createTextNode('Text Value'); 创建

不同节点对应的NodeType类型

此值可以通过 Node.nodeType 来获取。

1元素,2属性,3文本,8注释,9文档等比较常用。还有平常说的元素 其实指的是节点中得元素节点,所以说节点包含元素,节点还包括文本节点、实体节点等。

标签: #html中alignitems