萬盛學電腦網

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

HTML 超連結標籤 <a> 完整屬性、事件與 DOM 介面參考手冊

核心屬性

屬性說明
href目標 URL 或錨點 (#id)
target開啟目標:_blank/_self/_parent/_top/框架名稱
rel關係:nofollow/tag/license/alternate 等
hreflang目標資源語言代碼
typeMIME 類型提示
title工具提示文字
id / class識別與樣式鉤子
name錨點名稱 (HTML5 建議用 id)
charset目標資源字元集 (已淘汰)
coords / shape配合 image map 使用
accessKey快捷鍵
tabIndexTab 鍵順序

位置相關屬性 (Location 物件代理)

  • protocol、host、hostname、port、pathname、search (query string)、hash (fragment)
  • 可讀可寫,修改即導向新 URL

幾何屬性 (唯讀)

  • offsetLeft/Top/Width/Height:相對 offsetParent 座標
  • clientLeft/Top/Width/Height:內容區尺寸 (不含邊框/捲軸)
  • scrollLeft/Top/Width/Height:捲動相關

完整事件清單

DOM 介面成員 (節點操作)

  • parentNode、parentElement、firstChild、lastChild、nextSibling、previousSibling
  • nodeName、nodeType、nodeValue
  • ownerDocument、sourceIndex

現代最佳實踐

  • 語意化:導航用 <nav><ul><li><a>
  • 無障礙:aria-label、role="link" (非 a 標籤模擬連結時)
  • 安全性:外部連結加 rel="noopener noreferrer" 防 window.opener 攻擊
  • 效能:避免 javascript: 協定,改用事件監聽器
copyright © 萬盛學電腦網 all rights reserved
事件觸發時機
onclick左鍵點擊
ondblclick雙擊
onmousedown/up/move/over/out滑鼠動作
onfocus/blur焦點獲得/失去
onkeydown/keypress/keyup鍵盤
onactivate/deactivate元素啟用/停用 (IE)
onbeforecopy/cut/paste剪貼板前
oncopy/cut/paste剪貼板後
ondrag/start/end/enter/leave/drop拖曳 (HTML5)
oncontextmenu右鍵選單