<!DOCTYPE html>
<html>
<head>
	<title>Change h3 color</title>
	<script>
		window.onload = function() {
			var h3Tags = document.getElementsByTagName("h3");
			var currentIndex = 0;
			var intervalId = setInterval(function() {
				if (currentIndex >= h3Tags.length) {
					clearInterval(intervalId);
					return;
				}
				if (currentIndex > 0) {
					h3Tags[currentIndex - 1].style.color = "black";
				}
				h3Tags[currentIndex].style.color = "red";
				currentIndex++;
			}, 1000);
		};
	</script>
</head>
<body>
	<h3>Heading 1</h3>
	<h3>Heading 2</h3>
	<h3>Heading 3</h3>
	<h3>Heading 4</h3>
	<h3>Heading 5</h3>
</body>
</html
5个h3标签 使用js按照顺序改变颜色 颜色改为红色 改变后上一个标签恢复默认 一秒改变一次 定时执行 完整代码 vscode

原文地址: https://www.cveoy.top/t/topic/dq1w 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录