40 lines
991 B
HTML
40 lines
991 B
HTML
<!DOCTYPE html>
|
||
<html>
|
||
<head>
|
||
<meta charset="utf-8" />
|
||
<meta name="author" content="flykhan" />
|
||
<meta name="keywords" content="c c++ 物联网" />
|
||
<title>DOM操作</title>
|
||
|
||
<style>
|
||
.large_span {
|
||
font-size: 25px;
|
||
color: red;
|
||
padding: 1px;
|
||
border: 1px solid greenyellow;
|
||
margin: 5px;
|
||
}
|
||
</style>
|
||
</head>
|
||
|
||
<body>
|
||
<span name="sex">a</span>
|
||
<span name="sex">b</span>
|
||
<span class="item">c</span>
|
||
<span class="item">d</span>
|
||
<span class="item">e</span>
|
||
<script>
|
||
// js 的延迟器, 2000 毫秒之后执行匿名函数(箭头函数)
|
||
setTimeout(() => {
|
||
// 返回的是NodeList(节点列表)
|
||
|
||
// 获取所有的span标签,添加一个新的类名 large_span
|
||
let spans3 = document.getElementsByTagName("span");
|
||
for (let i in spans3) {
|
||
spans3[i].className += " large_span";
|
||
}
|
||
}, 2000);
|
||
</script>
|
||
</body>
|
||
</html>
|