自定义属性设置
作者:
王远清orz | 来源:发表于
2019-10-09 17:31 被阅读0次<body>
<div id="box" age="18" name="1">张三</div>
<script>
var box = document.getElementById('box');
console.log(box.id); //box
console.log(box.age); //undefined
console.log(box.name); //undefined
// 获取自定义属性的值 getAttribute
console.log(box.getAttribute('age'));
//设置自定义属性
box.setAttribute('age','20');
console.log(box.getAttribute('age'));
//移除自定义属性
box.removeAttribute('age','name');
</script>
</body>
本文标题:自定义属性设置
本文链接:https://www.haomeiwen.com/subject/wghgpctx.html
网友评论