HTML DOM removeNamedItem() 方法
HTML DOM removeNamedItem() 方法使用其名稱從 HTML 文件中的屬性節點刪除其引數中指定的一個節點。
語法
以下是語法 -
node.removeNamedItem(node);
示例
讓我們來看一個 removeNamedItem() 方法的示例 -
<!DOCTYPE html>
<html>
<head>
<style>
html{
height:100%;
}
body{
text-align:center;
color:#fff;
background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%) center/cover no-repeat;
height:100%;
}
.btn{
background:#0197F6;
border:none;
height:2rem;
border-radius:2px;
width:60%;
margin:2rem auto;
display:block;
color:#fff;
outline:none;
cursor:pointer;
}
</style>
</head>
<body>
<h1>DOM removeNamedItem() method Demo</h1>
<p style="color:#db133a;font-size:1.2rem;">Hi! I'm a para element in HTML with some random text</p>
<button onclick="remove()" class="btn">Remove Attribute using removeNamedItem() method</button>
<script>
function remove() {
var p=document.querySelector("p");
p.attributes.removeNamedItem("style");
}
</script>
</body>
</html>輸出
將生成以下輸出 -
_method.jpg)
點選“使用 removeNamedItem() 方法刪除屬性”按鈕可從 <p> 元素刪除 style 屬性。
_method_ex.jpg)
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP