<script>
var titles = document.querySelectorAll("#title>li")
var contents = document.querySelectorAll("#content>li")
// 循环遍历标题
for (var i = 0; i < titles.length; i++) {
titles[i].onclick = function () {
for (var j = 0; j < titles.length; j++) {
// 判断单击的是否是当前的标题
if (this == titles[j]) {
this.style.backgroundColor = "pink"
// 因为标题跟内容的索引一样
contents[j].style.display = "block"
} else {
titles[j].style.backgroundColor = "aqua"
contents[j].style.display = "none"
}
}
}
}
</script>
5、tab切换案例
最新推荐文章于 2024-09-02 10:21:44 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)