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