萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 網頁製作 >> HTML5 教學

HTML DOM 元素對象完整參考:從語義標籤到 Web Components

HTML 元素與 DOM 接口映射

每個 HTML 元素在 DOM 中都對應一個特定的接口類型,繼承自 `HTMLElement` → `Element` → `Node` → `EventTarget`。理解這層映射,是精通原生 DOM 操作、編寫類型定義、開發 Web Components 的基礎。

核心元素分類與對應接口

文檔結構

標籤DOM 接口關鍵屬性/方法
```HTMLHtmlElement``version`(廢棄)
```HTMLHeadElement`—
```HTMLBodyElement``onload`、`onunload`、`onafterprint`、`onbeforeprint`、`onbeforeunload`、`onhashchange`、`onmessage`、`onoffline`、`ononline`、`onpagehide`、`onpageshow`、`onpopstate`、`onstorage`
``</td><td>`HTMLTitleElement`</td><td>`text`</td></tr> <tr><td>`<base>`</td><td>`HTMLBaseElement`</td><td>`href`、`target`</td></tr> <tr><td>`<link>`</td><td>`HTMLLinkElement`</td><td>`href`、`rel`、`media`、`hreflang`、`type`、`sizes`、`crossorigin`、`referrerPolicy`、`as`、`integrity`、`fetchPriority`、`blocking`</td></tr> <tr><td>`<meta>`</td><td>`HTMLMetaElement`</td><td>`name`、`content`、`httpEquiv`、`charset`、`media`</td></tr> <tr><td>`<style>`</td><td>`HTMLStyleElement`</td><td>`media`、`type`、`title`、`disabled`、`sheet` (CSSStyleSheet)</td></tr> <tr><td>`<script>`</td><td>`HTMLScriptElement`</td><td>`src`、`type`、`async`、`defer`、`crossorigin`、`integrity`、`referrerPolicy`、`fetchPriority`、`blocking`、`text`、`noModule`</td></tr> <tr><td>`<noscript>`</td><td>`HTMLElement`</td><td>—</td></tr> <tr><td>`<template>`</td><td>`HTMLTemplateElement`</td><td>`content` (DocumentFragment)</td></tr> </tbody> </table> <h3>區塊語義</h3> <table> <thead><tr><th>標籤</th><th>DOM 接口</th><th>備註</th></tr></thead> <tbody> <tr><td>`<header>`/`<footer>`/`<main>`/`<section>`/`<article>`/`<aside>`/`<nav>`/`<h1>-<h6>`/`<p>`/`<hr>`/`<pre>`/`<blockquote>`/`<div>`</td><td>`HTMLElement`</td><td>共用通用接口,語義由標籤名體現</td></tr> <tr><td>`<address>`</td><td>`HTMLElement`</td><td>聯繫信息</td></tr> <tr><td>`<figure>`</td><td>`HTMLElement`</td><td>配合 `<figcaption>`</td></tr> <tr><td>`<figcaption>`</td><td>`HTMLElement`</td><td>—</td></tr> </tbody> </table> <h3>文本語義</h3> <table> <thead><tr><th>標籤</th><th>DOM 接口</th><th>備註</th></tr></thead> <tbody> <tr><td>`<a>`</td><td>`HTMLAnchorElement`</td><td>`href`、`target`、`rel`、`hreflang`、`type`、`text`、`protocol`、`host`、`hostname`、`port`、`pathname`、`search`、`hash`、`origin`、`password`、`username`、`referrerPolicy`</td></tr> <tr><td>`<em>`/`<strong>`/`<small>`/`<s>`/`<cite>`/`<q>`/`<dfn>`/`<abbr>`/`<ruby>`/`<rt>`/`<rp>`/`<data>`/`<time>`/`<code>`/`<var>`/`<samp>`/`<kbd>`/`<sub>`/`<sup>`/`<i>`/`<b>`/`<u>`/`<mark>`/`<bdi>`/`<bdo>`/`<span>`/`<br>`/`<wbr>`</td><td>`HTMLElement`</td><td>通用語義標籤</td></tr> <tr><td>`<ins>`/`<del>`</td><td>`HTMLModElement`</td><td>`cite`、`dateTime`</td></tr> </tbody> </table> <h3>列表與內容分組</h3> <table> <thead><tr><th>標籤</th><th>DOM 接口</th><th>關鍵屬性</th></tr></thead> <tbody> <tr><td>`<ul>`/`<ol>`</td><td>`HTMLOListElement`</td><td>`reversed`、`start`、`type`、`compact`(廢棄)</td></tr> <tr><td>`<li>`</td><td>`HTMLLIElement`</td><td>`value`(`<ol>` 子項編號)</td></tr> <tr><td>`<dl>`/`<dt>`/`<dd>`</td><td>`HTMLDListElement`/`HTMLElement`</td><td>—</td></tr> <tr><td>`<menu>`</td><td>`HTMLMenuElement`</td><td>`label`、`type`(廢棄)</td></tr> </tbody> </table> <h3>表格</h3> <table> <thead><tr><th>標籤</th><th>DOM 接口</th><th>關鍵屬性/方法</th></tr></thead> <tbody> <tr><td>`<table>`</td><td>`HTMLTableElement`</td><td>`caption`、`tHead`、`tFoot`、`tBodies`、`rows`、`createTHead()`、`deleteTHead()`、`createTFoot()`、`deleteTFoot()`、`createCaption()`、`deleteCaption()`、`insertRow()`、`deleteRow()`</td></tr> <tr><td>`<caption>`</td><td>`HTMLTableCaptionElement`</td><td>—</td></tr> <tr><td>`<thead>`/`<tbody>`/`<tfoot>`</td><td>`HTMLTableSectionElement`</td><td>`rows`、`insertRow()`、`deleteRow()`</td></tr> <tr><td>`<tr>`</td><td>`HTMLTableRowElement`</td><td>`rowIndex`、`sectionRowIndex`、`cells`、`insertCell()`、`deleteCell()`</td></tr> <tr><td>`<th>`/`<td>`</td><td>`HTMLTableCellElement`</td><td>`cellIndex`、`colSpan`、`rowSpan`、`headers`、`scope`、`abbr`、`align`/`vAlign`/`bgColor`(廢棄)</td></tr> <tr><td>`<colgroup>`</td><td>`HTMLTableColElement`</td><td>`span`</td></tr> <tr><td>`<col>`</td><td>`HTMLTableColElement`</td><td>`span`</td></tr> </tbody> </table> <h3>表單</h3> <table> <thead><tr><th>標籤</th><th>DOM 接口</th><th>關鍵屬性/方法</th></tr></thead> <tbody> <tr><td>`<form>`</td><td>`HTMLFormElement`</td><td>`elements`、`length`、`action`、`method`、`target`、`enctype`、`acceptCharset`、`autocomplete`、`noValidate`、`submit()`、`reset()`、`checkValidity()`、`reportValidity()`、`requestSubmit()`</td></tr> <tr><td>`<input>`</td><td>`HTMLInputElement`</td><td>`type`、`value`、`checked`、`files`、`validity`、`validationMessage`、`willValidate`、`checkValidity()`、`reportValidity()`、`setCustomValidity()`、`select()`、`setRangeText()`、`setSelectionRange()`、`stepUp()`、`stepDown()`、`labels`</td></tr> <tr><td>`<textarea>`</td><td>`HTMLTextAreaElement`</td><td>`value`、`textLength`、`selectionStart`/`End`/`Direction`、`setRangeText()`、`setSelectionRange()`</td></tr> <tr><td>`<select>`</td><td>`HTMLSelectElement`</td><td>`options`、`selectedIndex`/`Options`、`value`、`multiple`、`size`、`required`、`add()`、`remove()`、`item()`/`namedItem()`</td></tr> <tr><td>`<option>`</td><td>`HTMLOptionElement`</td><td>`value`、`text`、`selected`、`defaultSelected`、`disabled`、`label`、`index`</td></tr> <tr><td>`<optgroup>`</td><td>`HTMLOptGroupElement`</td><td>`label`、`disabled`</td></tr> <tr><td>`<button>`</td><td>`HTMLButtonElement`</td><td>`type`(`submit`/`reset`/`button`)、`disabled`、`form`、`formAction`、`formMethod`、`formEnctype`、`formTarget`、`formNoValidate`、`value`、`labels`</td></tr> <tr><td>`<fieldset>`</td><td>`HTMLFieldSetElement`</td><td>`disabled`、`form`、`elements`、`type`、`name`、`validationMessage`、`willValidate`、`checkValidity()`、`reportValidity()`</td></tr> <tr><td>`<legend>`</td><td>`HTMLLegendElement`</td><td>`form`</td></tr> <tr><td>`<label>`</td><td>`HTMLLabelElement`</td><td>`htmlFor` (`for`)、`control`、`form`</td></tr> <tr><td>`<output>`</td><td>`HTMLOutputElement`</td><td>`for`、`form`、`name`、`value`、`defaultValue`、`labels`</td></tr> <tr><td>`<progress>`</td><td>`HTMLProgressElement`</td><td>`value`、`max`、`position`、`labels`</td></tr> <tr><td>`<meter>`</td><td>`HTMLMeterElement`</td><td>`value`、`min`/`max`/`low`/`high`/`optimum`、`labels`</td></tr> <tr><td>`<datalist>`</td><td>`HTMLDataListElement`</td><td>`options`</td></tr> </tbody> </table> <h3>多媒體與嵌入</h3> <table> <thead><tr><th>標籤</th><th>DOM 接口</th><th>關鍵 API</th></tr></thead> <tbody> <tr><td>`<img>`</td><td>`HTMLImageElement`</td><td>`src`、`srcset`、`sizes`、`alt`、`crossorigin`、`loading`、`decoding`、`fetchPriority`、`width`/`height`、`naturalWidth`/`Height`、`complete`、`currentSrc`、`x`/`y`、`useMap`、`isMap`、`referrerPolicy`、`sizes`、`srcset`</td></tr> <tr><td>`<picture>`</td><td>`HTMLPictureElement`</td><td>—</td></tr> <tr><td>`<source>`</td><td>`HTMLSourceElement`</td><td>`src`、`type`、`srcset`、`sizes`、`media`、`width`/`height`</td></tr> <tr><td>`<video>`</td><td>`HTMLVideoElement`</td><td>繼承 `HTMLMediaElement`:`src`、`currentSrc`、`crossorigin`、`preload`、`autoplay`、`loop`、`muted`、`controls`、`width`/`height`/`videoWidth`/`Height`、`poster`、`playsInline`、`buffered`、`seekable`/`played`/`ended`、`playbackRate`、`defaultPlaybackRate`、`volume`、`muted`、`error`、`networkState`、`readyState`、`canPlayType()`、`load()`、`play()`、`pause()`、`addTextTrack()`、`getVideoPlaybackQuality()`、`requestPictureInPicture()`、`requestFullscreen()`</td></tr> <tr><td>`<audio>`</td><td>`HTMLAudioElement`</td><td>繼承 `HTMLMediaElement`(無視頻屬性)</td></tr> <tr><td>`<track>`</td><td>`HTMLTrackElement`</td><td>`kind`、`src`、`srclang`、`label`、`default`、`readyState`、`track` (TextTrack)</td></tr> <tr><td>`<canvas>`</td><td>`HTMLCanvasElement`</td><td>`width`/`height`、`getContext('2d'/'webgl'/'webgl2'/'bitmaprenderer')`、`toDataURL()`、`toBlob()`、`transferControlToOffscreen()`、`captureStream()`</td></tr> <tr><td>`<iframe>`</td><td>`HTMLIFrameElement`</td><td>`src`、`srcdoc`、`name`、`sandbox`、`allow`、`allowFullscreen`、`allowPaymentRequest`、`referrerPolicy`、`loading`、`contentDocument`、`contentWindow`、`getSVGDocument()`</td></tr> <tr><td>`<embed>`</td><td>`HTMLEmbedElement`</td><td>`src`、`type`、`width`/`height`、`getSVGDocument()`</td></tr> <tr><td>`<object>`</td><td>`HTMLObjectElement`</td><td>`data`、`type`、`typeMustMatch`、`name`、`form`、`width`/`height`、`contentDocument`、`contentWindow`、`useMap`、`validationMessage`、`willValidate`、`checkValidity()`、`reportValidity()`</td></tr> <tr><td>`<param>`</td><td>`HTMLParamElement`</td><td>`name`、`value`</td></tr> <tr><td>`<map>`</td><td>`HTMLMapElement`</td><td>`name`、`areas`、`images`</td></tr> <tr><td>`<area>`</td><td>`HTMLAreaElement`</td><td>`alt`、`coords`、`shape`、`href`、`target`、`rel`、`referrerPolicy`、`ping`、`hash`/`host`/`hostname`/`pathname`/`port`/`protocol`/`search`/`origin`/`username`/`password`</td></tr> </tbody> </table> <h3>交互與腳本</h3> <table> <thead><tr><th>標籤</th><th>DOM 接口</th><th>關鍵特性</th></tr></thead> <tbody> <tr><td>`<details>`</td><td>`HTMLDetailsElement`</td><td>`open`、`toggle` 事件</td></tr> <tr><td>`<summary>`</td><td>`HTMLElement`</td><td>—</td></tr> <tr><td>`<dialog>`</td><td>`HTMLDialogElement`</td><td>`open`、`returnValue`、`show()`、`showModal()`、`close()`、`close` 事件、`cancel` 事件</td></tr> <tr><td>`<slot>`</td><td>`HTMLSlotElement`</td><td>`name`、`assignedNodes()`/`assignedElements()`、`slotchange` 事件</td></tr> </tbody> </table> <h3>已廢棄/遺留元素(僅兼容)</h3> <p>`<applet>`、`<acronym>`、`<bgsound>`、`<dir>`、`<frame>`/`<frameset>`/`<noframes>`、`<isindex>`、`<listing>`/`<plaintext>`/`<xmp>`、`<nextid>`、`<marquee>`、`<nobr>`、`<basefont>`、`<font>`、`<center>`、`<strike>`、`<tt>`、`<big>`、`<blink>`、`<comment>`、`<spacer>`、`<keygen>`、`<rb>`/`<rtc>`(Ruby 相關)</p> <h2>Web Components 核心接口</h2> <ul> <li>`CustomElementRegistry`:`define(name, constructor, options)`、`get(name)`、`whenDefined(name)`、`upgrade(root)`</li> <li>`ShadowRoot`:`mode` (`open`/`closed`)、`host`、`innerHTML`、`adoptedStyleSheets`、`delegatesFocus`、`slotAssignment`、`getAnimations()`、`onslotchange`</li> <li>`HTMLSlotElement`:`name`、`assignedNodes({flatten:true})`、`assignedElements()`、`slotchange`</li> <li>`ElementInternals`:`form`、`validity`、`validationMessage`、`willValidate`、`checkValidity()`、`reportValidity()`、`setFormValue()`、`setValidity()`、`labels`、`aria*`、`role`、`shadowRoot`、`states`、`anchor`</li> </ul> <h2>總結</h2> <p>HTML 元素到 DOM 接口的映射,構建了 Web 平台的類型系統骨架。熟悉核心元素的專屬接口屬性方法,能編寫類型安全、高性能、語義正確的 DOM 操作代碼,也是開發高質量 Web Components 的前提。</p> <div class="ad2"> <script language='javascript' src='/ad/tad.js'></script> </div> </div> <div> <div class="pageNum"> <ul> <li>上一篇程序編程: <a class='LinkPrevArticle' href='https://twcomputer.wsxdn.com/programming/webproduction/html5/201510/157913.html' >HTML 三大列表類型完全指南:ul、ol、dl 語義化與樣式控制</a> <li>下一篇程序編程: <a class='LinkNextArticle' href='https://twcomputer.wsxdn.com/programming/webproduction/html5/201510/157915.html' >HTML 事件屬性完整參考:從內聯處理器到現代事件模型</a> </ul> </div> </div> <div class=kenbxne_js></div> </div> <div class=kenbxne_js></div> </div> <div class=kenbxne_js></div> <div class=hebxbne_left-div-2> <h2 style="text-align:left">HTML5 教學排行</h2> <ul> <li><a class="font7 nleft" title="HTML 程式碼核心架構解析:Head 與 Body 兩大區塊詳細說明" href="https://twcomputer.wsxdn.com/programming/webproduction/html5/201601/170640.html">HTML 程式碼核心架構解析:Head 與 Body 兩大區塊詳細說明</a></li> <li><a class="font7 nleft" title="HTML 縮排與空白字元: 、 、 、CSS text-in…" href="https://twcomputer.wsxdn.com/programming/webproduction/html5/201510/157388.html">HTML 縮排與空白字元: 、 、 、CSS text-in…</a></li> <li><a class="font7 nleft" title="HTML 標籤正則表達式:匹配與解析的陷阱與最佳替代方案" href="https://twcomputer.wsxdn.com/programming/webproduction/html5/201512/166284.html">HTML 標籤正則表達式:匹配與解析的陷阱與最佳替代方案</a></li> <li><a class="font7 nleft" title="11 個實用行動網頁開發框架與工具:Lungo.js、Sencha Touch、…" href="https://twcomputer.wsxdn.com/programming/webproduction/html5/201510/35370.html">11 個實用行動網頁開發框架與工具:Lungo.js、Sencha Touch、…</a></li> <li><a class="font7 nleft" title="HTML 文字排版標籤:sub、sup、pre、wbr 與語義化標記" href="https://twcomputer.wsxdn.com/programming/webproduction/html5/201512/165331.html">HTML 文字排版標籤:sub、sup、pre、wbr 與語義化標記</a></li> </ul> </div> <div class=kenbxne_js></div> </div> <div class="nright hebxbne_right"> <div class=guanggao1 id=guanggao_r1></div> <div class=kenbxne_js></div> <div class=hebxbne_right-div1> <h2>推薦文章</h2> <div class=kenbxne_js></div> <ul class=hebxbne_right-list1> <li><a class="font7 nleft" title="HTML/CSS 前端核心英文詞彙速查表:從 A 到 Z 完整收錄" href="https://twcomputer.wsxdn.com/programming/webproduction/html5/201510/157712.html">HTML/CSS 前端核心英文詞彙速查表:從 A 到 Z 完整收錄</a></li> <li><a class="font7 nleft" title="HTML 註解的實戰價值:從代碼可讀性到團隊協作與維護效率" href="https://twcomputer.wsxdn.com/programming/webproduction/html5/201510/157587.html">HTML 註解的實戰價值:從代碼可讀性到團隊協作與維護效率</a></li> <li><a class="font7 nleft" title="紐約時報如何以 HTML5 打造優質線上閱讀產品" href="https://twcomputer.wsxdn.com/programming/webproduction/html5/201510/35375.html">紐約時報如何以 HTML5 打造優質線上閱讀產品</a></li> <li><a class="font7 nleft" title="HTML 表格 <table> 完整教程:結構、屬性、合併單元格、無障礙與響應式…" href="https://twcomputer.wsxdn.com/programming/webproduction/html5/201511/162777.html">HTML 表格 <table> 完整教程:結構、屬性、合併單元格、無障礙與響應式…</a></li> <li><a class="font7 nleft" title="HTML 文字格式化完整指南:語意標籤、CSS 樣式與無障礙最佳實踐" href="https://twcomputer.wsxdn.com/programming/webproduction/html5/201510/157593.html">HTML 文字格式化完整指南:語意標籤、CSS 樣式與無障礙最佳實踐</a></li> <li><a class="font7 nleft" title="HTML 標籤註釋完整指南:語法、用途與最佳實踐" href="https://twcomputer.wsxdn.com/programming/webproduction/html5/201511/164257.html">HTML 標籤註釋完整指南:語法、用途與最佳實踐</a></li> <li><a class="font7 nleft" title="HTML5 contenteditable 屬性完整規範與編輯狀態繼承機制" href="https://twcomputer.wsxdn.com/programming/webproduction/html5/201510/35519.html">HTML5 contenteditable 屬性完整規範與編輯狀態繼承機制</a></li> <li><a class="font7 nleft" title="HTML5 圖片預覽實作指南:URL.createObjectURL 與 Fil…" href="https://twcomputer.wsxdn.com/programming/webproduction/html5/201510/157736.html">HTML5 圖片預覽實作指南:URL.createObjectURL 與 Fil…</a></li> <li><a class="font7 nleft" title="HTML5 離線存儲實戰:Web SQL Database CRUD 完整指南(…" href="https://twcomputer.wsxdn.com/programming/webproduction/html5/201510/35569.html">HTML5 離線存儲實戰:Web SQL Database CRUD 完整指南(…</a></li> <li><a class="font7 nleft" title="HTML `<div>` 標籤完全指南:語意、佈局、樣式隔離與現代最佳實踐" href="https://twcomputer.wsxdn.com/programming/webproduction/html5/201510/157644.html">HTML `<div>` 標籤完全指南:語意、佈局、樣式隔離與現代最佳實踐</a></li> </ul> </div> </div> <div class=kenbxne_js></div> </div> <div class=kenbxne_js></div> <div class=plnebxmj> <div class="plnebxmj-2 flink"> <h2><a class=bottom href="https://twcomputer.wsxdn.com/" target=_blank>萬盛學電腦網</a>| <a class=bottom hreflang="ja" href="https://jp.wsxdn.com/" target=_blank>日本語版</a> | <a class=bottom onclick="this.style.behavior='url(#default#homepage)';this.sethomepage('https://twcomputer.wsxdn.com');" href="#">設為首頁</a> | <a class=bottom href="javascript:window.external.addfavorite('https://twcomputer.wsxdn.com','萬盛學電腦網');">加入收藏</a></h2> </div> <div class=knemnnx></div> </div> <div class="ojwbxnks">copyright © <a title="萬盛學電腦網" href="https://twcomputer.wsxdn.com/" target=_blank>萬盛學電腦網</a> all rights reserved <br> </div> </div> </body> </html>