<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>自定义属性操作 </title>
</head>
<body>
<div id="box">李华</div>
<script type="text/javascript">
var box = document.getElementById('box');
//给DOM添加属性
box.setAttribute('age','18');
box.setAttribute('class','Lname');
//获取给DOM自定义添加的一些属性
console.log(box.getAttribute('age'));
console.log(box.getAttribute('class'));
//移除给DOM自定义添加的一些属性
box.removeAttribute('age');
box.removeAttribute('id');
</script>
</body>
</html>
webAPI03-13自定义属性操作
最新推荐文章于 2022-03-27 20:23:25 发布