自定义标签及属性
2019-04-16 本文已影响0人
郭先生_515
主要是在html元素上通过xmlns绑定自定义标签名即可 ----> xmlns:myhtml
<!DOCTYPE html>
<html xmlns:myhtml>
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.custom {
font-size: 18px;
font-weight: bold;
color: red;
}
p{
color: green;
}
</style>
</head>
<body>
<myhtml class="custom" id="custom" myattr="attrs">this is my html element!</myhtml>
</body>
<script>
// 获取自定义属性
console.log(document.getElementById('custom').getAttribute('myattr'))
// 设置自定义属性
document.getElementById('custom').setAttribute('myattr123', 12345)
</script>
</html>