当前位置: 首页> 健康> 知识 > js学习--制作选项卡

js学习--制作选项卡

时间:2025/8/23 8:21:06来源:https://blog.csdn.net/z16638522031/article/details/140162946 浏览次数:0次

选项卡制作

<!DOCTYPE html>
<html lang="zh"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><style>.text_one {width: 11.4%;height: 200px;}</style></head><body><div style="display: flex;justify-content: center;"><div class="option_one" style="background-color: red;">选项卡1</div><div class="option_one" style="background-color: aqua;">选项卡2</div><div class="option_one" style="background-color: aqua;">选项卡3</div></div><div style="display: flex;justify-content: center;"><div class="text_one" style="background-color: beige;">内容1</div><div class="text_one" style="background-color: yellow;display: none;">内容2</div><div class="text_one" style="background-color: skyblue;display: none;">内容3</div></div><script>let a = document.getElementsByClassName('option_one');let t = document.getElementsByClassName('text_one');console.log(a);console.log(t);for (let i = 0; i < a.length; i++) {a[i].addEventListener('click', function() {console.log(i);for (let j = 0; j < t.length; j++) {if(i==j){a[j].style.background = 'red';t[j].style.display = 'block';} else {a[j].style.background = 'aqua';t[j].style.display = 'none';}}})}</script></body>
</html>

关键字:js学习--制作选项卡

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: