jq 实现简单tab切换

淡淡的烟草味﹌ 2023-03-12 09:02 242阅读 0赞
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <style>
  8. .navigation p {
  9. float: left;
  10. margin: 0px 20px;
  11. }
  12. .navigation {
  13. overflow: hidden;
  14. }
  15. .box+.box {
  16. display: none;
  17. }
  18. </style>
  19. </head>
  20. <body>
  21. <div class="navigation">
  22. <p class="a">哈哈1</p>
  23. <p class="a">哈哈2</p>
  24. <p class="a">哈哈3</p>
  25. </div>
  26. <div class="box">1</div>
  27. <div class="box">2</div>
  28. <div class="box">3</div>
  29. <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.slim.js"></script>
  30. <script>
  31. $(function () {
  32. $(".navigation .a").each(function (i) {
  33. $(this).click(function () {
  34. $(".box").eq(i).show();
  35. $(".box").not($(".box").eq(i)).hide();
  36. $(".navigation .a").removeClass("checked");
  37. $(this).addClass("checked");
  38. })
  39. })
  40. })
  41. </script>
  42. </body>
  43. </html>

发表评论

表情:
评论列表 (有 0 条评论,242人围观)

还没有评论,来说两句吧...

相关阅读