Change H3 Color

Heading 1

Heading 2

Heading 3

Heading 4

Heading 5

<script>
	// 获取所有h3标签
	let h3List = document.getElementsByTagName("h3");
	// 初始化当前标签索引
	let currentIndex = 0;

	// 定义颜色改变函数
	function changeColor() {
		// 获取当前标签
		let currentH3 = h3List[currentIndex];
		// 改变当前标签颜色为红色
		currentH3.style.color = "red";
		// 如果当前标签不是第一个标签,则将上一个标签颜色恢复默认
		if (currentIndex > 0) {
			let previousH3 = h3List[currentIndex - 1];
			previousH3.style.color = "";
		}
		// 更新当前标签索引
		currentIndex = (currentIndex + 1) % h3List.length;
	}

	// 每隔一秒执行一次颜色改变函数
	setInterval(changeColor, 1000);
</script>

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

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