- HTML 教程
- HTML - 首頁
- HTML - 路線圖
- HTML - 簡介
- HTML - 歷史與演變
- HTML - 編輯器
- HTML - 基本標籤
- HTML - 元素
- HTML - 屬性
- HTML - 標題
- HTML - 段落
- HTML - 字型
- HTML - 塊
- HTML - 樣式表
- HTML - 格式化
- HTML - 引號
- HTML - 註釋
- HTML - 顏色
- HTML - 圖片
- HTML - 圖片地圖
- HTML - 內聯框架
- HTML - 短語元素
- HTML - 元標籤
- HTML - 類
- HTML - ID
- HTML - 背景
- HTML 表格
- HTML - 表格
- HTML - 表格標題和標題
- HTML - 表格樣式
- HTML - 表格 Colgroup
- HTML - 巢狀表格
- HTML 列表
- HTML - 列表
- HTML - 無序列表
- HTML - 有序列表
- HTML - 定義列表
- HTML 連結
- HTML - 文字連結
- HTML - 圖片連結
- HTML - 郵件連結
- HTML 顏色名稱和值
- HTML - 顏色名稱
- HTML - RGB
- HTML - HEX
- HTML - HSL
- HTML 表單
- HTML - 表單
- HTML - 表單屬性
- HTML - 表單控制元件
- HTML - 輸入屬性
- HTML 媒體
- HTML - 影片元素
- HTML - 音訊元素
- HTML - 嵌入多媒體
- HTML 頁首
- HTML - 頭元素
- HTML - 新增 Favicon
- HTML - Javascript
- HTML 佈局
- HTML - 佈局
- HTML - 佈局元素
- HTML - 使用 CSS 進行佈局
- HTML - 響應式設計
- HTML - 符號
- HTML - 表情符號
- HTML - 樣式指南
- HTML 圖形
- HTML - SVG
- HTML - Canvas
- HTML API
- HTML - 地理位置 API
- HTML - 拖放 API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web 儲存
- HTML - 伺服器傳送事件
- HTML 雜項
- HTML - 文件物件模型 (DOM)
- HTML - MathML
- HTML - 微資料
- HTML - IndexedDB
- HTML - Web 訊息傳遞
- HTML - Web CORS
- HTML - Web RTC
- HTML 演示
- HTML - 音訊播放器
- HTML - 影片播放器
- HTML - 網頁幻燈片
- HTML 工具
- HTML - Velocity Draw
- HTML - 二維碼
- HTML - Modernizer
- HTML - 驗證
- HTML - 顏色拾取器
- HTML 參考
- HTML - 速查表
- HTML - 標籤參考
- HTML - 屬性參考
- HTML - 事件參考
- HTML - 字型參考
- HTML - ASCII 碼
- ASCII 表格查詢
- HTML - 顏色名稱
- HTML - 實體
- MIME 媒體型別
- HTML - URL 編碼
- 語言 ISO 程式碼
- HTML - 字元編碼
- HTML - 已棄用標籤
- HTML 資源
- HTML - 快速指南
- HTML - 有用資源
- HTML - 顏色程式碼生成器
- HTML - 線上編輯器
HTML - DOM 元素 removeAttributeNode() 方法
removeAttributeNode() 方法允許您從元素中刪除特定的屬性節點。
語法
element.removeAttributeNode(attributeNode)
引數
此方法接受如下所述的單個引數。
| 引數 | 描述 |
|---|---|
| attributeNode | 您要從元素中刪除的節點物件。 |
返回值
removeAttributeNode() 方法返回從元素中刪除的屬性節點。
HTML DOM 元素“removeAttributeNode()”方法示例
以下是在 HTML DOM 元素中不同場景下使用 removeAttributeNode() 方法的一些示例。
刪除自定義資料屬性節點
此示例演示瞭如何使用 removeAttributeNode() 方法從<div> 元素中刪除自定義資料屬性節點。
<!DOCTYPE html>
<html lang="en">
<head>
<title>Remove Custom Data Attribute Node</title>
</head>
<body>
<h1>HTML DOM Element</h1>
<h2>removeAttributeNode() Method</h2>
<p>Click the button below to remove a custom data
attribute node from the <div> element.
</p>
<div id="my" data-info="custom">
This div has a custom data attribute.
</div><br>
<button onclick="removeDataAttributeNode()">
Remove data-info Attribute
</button>
<script>
function removeDataAttributeNode() {
const div = document.getElementById('my');
const attr=div.getAttributeNode('data-info');
if (attr) {
div.removeAttributeNode(attr);
document.getElementById('o').textContent=
'Data attribute removed successfully.';
} else {
document.getElementById('o').textContent=
'Data attribute not found.';
}
}
</script>
<div id="o"></div>
</body>
</html>
刪除 Href 屬性節點
此示例演示瞭如何使用 removeAttributeNode() 方法從元素中刪除 href 屬性節點。
<!DOCTYPE html>
<html lang="en">
<head>
<title>Remove Attribute Node</title>
</head>
<body>
<h1>HTML DOM Element</h1>
<h2>removeAttributeNode() Method</h2>
<p>Click the button below to remove the href
attribute from the anchor (<a>) element.
</p>
<a href="https://tutorialspoint.tw" id="my">
Visit tutorialspoint.com
</a><br><br>
<button onclick="removeHrefAttribute()">
Remove href Attribute
</button>
<div id="otpt"></div>
<script>
function removeHrefAttribute() {
const link = document.getElementById('my');
const hrefAttr=link.getAttributeNode('href');
link.removeAttributeNode(hrefAttr);
document.getElementById('otpt').textContent=
'Href attribute removed successfully.';
}
</script>
</body>
</html>
支援的瀏覽器
| 方法 | ![]() |
![]() |
![]() |
![]() |
![]() |
|---|---|---|---|---|---|
| removeAttributeNode() | 是 | 是 | 是 | 是 | 是 |
html_dom_element_reference.htm
廣告




