Oggetto Window Document
- Pagina precedente defaultStatus
- Pagina successiva focus()
- Torna alla pagina precedente Oggetto Window
Oggetto Document
Quando un documento HTML viene caricato nel browser web, diventa unOggetto documento.
Oggetto documentoè il nodo radice di un documento HTML.
Oggetto documentoÈOggetto finestradi seguito.
Accedi alle proprietàOggetto documento
:
window.document
o semplicemente document
Esempio
let url = window.document.URL;
let url = document.URL;
Proprietà e metodi dell'oggetto documento
Le seguenti proprietà e metodi sono disponibili per il documento HTML:
Proprietà / Metodo | Descrizione |
---|---|
activeElement | Restituisce l'elemento attualmente attivo del documento. |
addEventListener() | Aggiunge un gestore eventi al documento. |
adoptNode() | Adotta un nodo da un altro documento. |
anchors | 已弃用。 |
applets | 已弃用。 |
baseURI | Restituisce l'URI assoluto di riferimento del documento. |
body | Imposta o restituisce il corpo del documento (<body> element). |
charset | 已弃用。 |
characterSet | Restituisce la codifica di caratteri del documento. |
close() | Chiude lo stream di output aperto precedentemente con document.open(). |
cookie | Restituisce il nome/valore di tutti i cookie del documento. |
createAttribute() | Crea un nodo attributo. |
createComment() | Crea un nodo Comment con il testo specificato. |
createDocumentFragment() | Crea un nodo DocumentFragment vuoto. |
createElement() | Crea un nodo di elemento. |
createEvent() | Crea un nuovo evento. |
createTextNode() | Crea un nodo di testo. |
defaultView | Restituisce l'oggetto finestra associato al documento, se disponibile, altrimenti restituisce null. |
designMode | Controlla se l'intero documento dovrebbe essere modificabile. |
doctype | Restituisce la dichiarazione di tipo di documento associata al documento. |
documentElement | Restituisce l'elemento Document del documento (elemento <html>). |
documentMode | 已弃用。 |
documentURI | Imposta o restituisce la posizione del documento. |
domain | Restituisce il dominio del server che ha caricato il documento. |
domConfig | 已弃用。 |
embeds | Restituisce l'insieme di tutti gli elementi <embed> del documento. |
execCommand() | 已弃用。 |
forms | Restituisce l'insieme di tutti gli elementi <form> del documento. |
getElementById() | Restituisce l'elemento con l'attributo ID specificato. |
getElementsByClassName() | Restituisce l'insieme degli elementi che hanno il nome di classe specificato. HTMLCollection. |
getElementsByName() | Restituisce l'insieme degli elementi attivi che hanno il nome specificato. NodeList. |
getElementsByTagName() | Restituisce l'insieme degli elementi che hanno il nome di etichetta specificato. HTMLCollection. |
hasFocus() | Restituisce un valore booleano che indica se il documento ha l'attenzione. |
head | Restituisce l'elemento <head> del documento. |
images | Restituisce l'insieme di tutti gli elementi <img> del documento. |
implementation | 返回处理此文档的 DOMImplementation 对象。 |
importNode() | 从另一个文档导入节点。 |
inputEncoding | 已弃用。 |
lastModified | 返回文档最后一次修改的日期和时间。 |
links | 返回文档中所有拥有 href 属性的 <a> 和 <area> 元素的集合。 |
normalize() | 删除空文本节点,并连接相邻节点。 |
normalizeDocument() | 已弃用。 |
open() | 打开 HTML 输出流以收集来自 document.write() 的输出。 |
querySelector() | 返回与文档中指定的 CSS 选择器匹配的第一个元素。 |
querySelectorAll() | 返回包含与文档中指定的 CSS 选择器匹配的所有元素的静态 NodeList。 |
readyState | 返回文档的(加载)状态。 |
referrer | 返回加载当前文档的文档的 URL。 |
removeEventListener() | 从文档中删除事件处理程序(已使用 addEventListener() 方法 附加的)。 |
renameNode() | 已弃用。 |
scripts | 返回文档中 <script> 元素的集合。 |
strictErrorChecking | 已弃用。 |
title | 设置或返回文档的标题。 |
URL | 返回 HTML 文档的完整 URL。 |
write() | 将 HTML 表达式或 JavaScript 代码写入文档。 |
writeln() | 与 write() 相同,但在每条语句后添加换行符。 |
Document 对象描述
HTMLDocument 接口扩展了 DOM Document 接口,定义了 HTML 专用的属性和方法。
许多属性和方法都是 HTMLCollection 对象(实际上是可以用数组或名称索引的只读数组),其中保存了对锚、表单、链接以及其他可脚本元素的引用。
这些集合属性都源自于 0 级 DOM。它们已经被 Document.getElementsByTagName() 已被所取代,但仍然经常使用,因为它们非常方便。
write() 方法值得注意的是,在文档加载和解析时,它允许一个脚本向文档中插入动态生成的内容。
Attenzione, nel livello 1 DOM, HTMLDocument ha definito un'entità chiamata getElementById() un metodo molto utile. In 2 livello DOM, questo metodo è stato trasferito all'interfaccia Document, ora è ereditato da HTMLDocument invece di essere definito da esso.
- Pagina precedente defaultStatus
- Pagina successiva focus()
- Torna alla pagina precedente Oggetto Window