JavaScript 循环改变 H3 标签颜色 - 完整代码示例
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
<script>
var headings = document.getElementsByTagName('h3');
var currentIndex = 0;
function changeColor() {
headings[currentIndex].style.color = 'red';
if (currentIndex > 0) {
headings[currentIndex - 1].style.color = '';
} else {
headings[headings.length - 1].style.color = '';
}
currentIndex = (currentIndex + 1) % headings.length;
setTimeout(changeColor, 1000);
}
changeColor();
</script>
原文地址: https://www.cveoy.top/t/topic/kMBr 著作权归作者所有。请勿转载和采集!