JavaScript 语句参考手册JavaScript Array对象JavaScript Boolean对象JavaScript Date对象JavaScript Math对象JavaScript Number对象JavaScript String对象JavaScript RegExp对象JavaScript 全局JavaScript 运算符使用window 对象navigator 对象screen 对象history 对象location 对象HTML DOMDocument 对象HTML DOM 元素对象HTML DOM 属性对象HTML DOM 事件HTML DOM Anchor 对象HTML DOM Area 对象HTML DOM Audio 对象HTML DOM Base 对象HTML DOM Blockquote 对象HTML DOM Body 对象HTML DOM Button 对象HTML DOM Canvas 对象HTML DOM Column 对象HTML DOM Columngroup 对象HTML DOM Datalist 对象HTML DOM Del 对象HTML DOM Details 对象HTML DOM Dialog 对象HTML DOM Embed 对象HTML DOM Fieldset 对象HTML DOM Form 对象HTML DOM Frame 和 IFrame 对象HTML DOM Frameset 对象HTML DOM Image 对象HTML DOM ins 对象HTML DOM Button对象HTML DOM Checkbox 对象HTML DOM Input Color 对象HTML DOM Input Date 对象HTML DOM Input Datetime 对象HTML DOM Input DatetimeLocalHTML DOM Input Email 对象HTML DOM FileUpload 对象HTML DOM Hidden 对象HTML DOM Input Image 对象HTML DOM Input Month 对象HTML DOMInput Number对象HTML DOM Input Range 对象HTML DOM Password 对象HTML DOM Radio 对象HTML DOM Reset 对象HTML DOM Input Search 对象HTML DOM Submit 对象HTML DOM Input Text 对象HTML DOM Input Time对象HTML DOM Input URL 对象HTML DOM Input Week 对象HTML DOM Keygen 对象HTML DOM Link 对象HTML DOM Label 对象HTML DOM Legend 对象HTML DOM Li 对象HTML DOM Map 对象HTML DOM Menu 对象HTML DOM MenuItem 对象HTML DOM Meta 对象HTML DOM Meter 对象HTML DOM Object 对象HTML DOM Ol 对象HTML DOM OptionGroup 对象HTML DOM Option 对象HTML DOM Parameter 对象HTML DOM Progress 对象HTML DOM Quote 对象HTML DOM Script 对象HTML DOM Select 对象HTML DOM Source 对象HTML DOM Style 对象HTML DOM Table 对象HTML DOM td/th 对象HTML DOM TableHeader 对象HTML DOM HTMLTableRow 对象HTML DOM Textarea 对象HTML DOM Title 对象HTML DOM Time 对象HTML DOM Track 对象HTML DOM Video 对象

HTML DOMDocument 对象

html dom (Document Object Model) 中 , 每一个元素都是 节点

  • 文档是一个文档
  • 所有的HTML元素都是元素节点
  • 所有 HTML 属性都是属性节点
  • 文本插入到 HTML 元素是文本节点
  • 注释是注释节点


Document 对象

浏览器载入 HTML 文档, 它就会成为 document 对象

document 对象是 HTML 文档的根节点与所有其他节点 ( 元素节点,文本节点,属性节点, 注释节点 )

Document 对象使我们可以从脚本中对 HTML 页面中的所有元素进行访问

Document 对象是 Window 对象的一部分,可通过 window.document 属性对其进行访问


Document 对象属性和方法

HTML文档中可以使用以上属性和方法

属性 / 方法描述
document.activeElement返回当前获取焦点元素
document.addEventListener()向文档添加句柄
document.adoptNode(node)从另外一个文档返回 adapded 节点到当前文档
document.anchors返回对文档中所有 Anchor 对象的引用
document.applets返回对文档中所有 Applet 对象的引用
document.baseURI返回文档的绝对基础 URI
document.body返回文档的body元素
document.close()关闭用 document.open() 方法打开的输出流,并显示选定的数据
document.cookie设置或返回与当前文档有关的所有 cookie
document.createAttribute()创建一个属性节点
document.createComment()createComment() 方法可创建注释节点
document.createDocumentFragment()创建空的 DocumentFragment 对象,并返回此对象
document.createElement()创建元素节点
document.createTextNode()创建文本节点
document.doctype返回与文档相关的文档类型声明 (DTD)
document.documentElement返回文档的根节点
document.documentMode返回用于通过浏览器渲染文档的模式
document.documentURI设置或返回文档的位置
document.domain返回当前文档的域名
document.domConfig返回normalizeDocument()被调用时所使用的配置
document.embeds返回文档中所有嵌入的内容(embed)集合
document.forms返回对文档中所有 Form 对象引用
document. getElementsByClassName()返回文档中所有指定类名的元素集合,作为 NodeList 对象
document.getElementById()返回对拥有指定 id 的第一个对象的引用
document.getElementsByName()返回带有指定名称的对象集合
document.getElementsByTagName()返回带有指定标签名的对象集合
document.images返回对文档中所有 Image 对象引用
document.implementation返回处理该文档的 DOMImplementation 对象
document.importNode()把一个节点从另一个文档复制到该文档以便应用
document.inputEncoding返回用于文档的编码方式(在解析时)
document.lastModified返回文档被最后修改的日期和时间
document.links返回对文档中所有 Area 和 Link 对象引用
document.normalize()删除空文本节点,并连接相邻节点
document.normalizeDocument()删除空文本节点,并连接相邻节点的
document.open()打开一个流,以收集来自任何 document.write() 或 document.writeln() 方法的输出
document.querySelector()返回文档中匹配指定的css选择器的第一元素
document.querySelectorAll()document.querySelectorAll() 是 HTML5中引入的新方法,返回文档中匹配的CSS选择器的所有元素节点列表
document.readyState返回文档状态 (载入中……)
document.referrer返回载入当前文档的文档的 URL
document.removeEventListener()移除文档中的事件句柄(由 addEventListener() 方法添加)
document.renameNode()重命名元素或者属性节点
document.scripts返回页面中所有脚本的集合
document.strictErrorChecking设置或返回是否强制进行错误检查
document.title返回当前文档的标题
document.URL返回文档完整的URL
document.write()向文档写 HTML 表达式 或 JavaScript 代码
document.writeln()等同于 write() 方法,不同的是在每个表达式之后写一个换行符

警告 !!!

W3C DOM 核心,文档对象继承节点对象的所有属性和方法

很多属性和方法在文档中是没有意义的

HTML 文档对象应该避免使用这些节点对象和属性

属性 / 方法避免的原因
document.attributes文档没有该属性
document.hasAttributes()文档没有该属性
document.nextSibling文档没有下一节点
document.nodeName这个通常是 #document
document.nodeType这个通常是 9(DOCUMENT_NODE)
document.nodeValue文档没有一个节点值
document.ownerDocument文档没有主文档
document.ownerElement文档没有自己的节点
document.parentNode文档没有父节点
document.previousSibling文档没有兄弟节点
document.textContent文档没有文本节点

链接: https://www.fly63.com/course/10_614