<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
li{
font-size: 30px;
color: blue;
}
.lis{
font-size: 10px;
color: red;
}
</style>
</head>
<body>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
<button onclick="classname()">点击更改属性</button>
<script>
var lis = document.getElementsByTagName("li");
function classname() {
for (var i = 0; i < lis.length; i++) {
lis[i].className="lis";
}
}
</script>
</body>
</html>
动态添加class属性
猜你喜欢
转载自blog.csdn.net/gadxiong/article/details/80500295
今日推荐
周排行