qfedu-web/www/js11.html

40 lines
991 B
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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>