html代碼
創新互聯堅持“要么做到,要么別承諾”的工作理念,服務領域包括:成都做網站、成都網站制作、企業官網、英文網站、手機端網站、網站推廣等服務,滿足客戶于互聯網時代的薩迦網站設計、移動媒體設計的需求,幫助企業找到有效的互聯網解決方案。努力成為您成熟可靠的網絡建設合作伙伴!
實現簡單的tab框
css代碼
* { margin: 0; padding: 0px; } ul { width: 300px; margin: 10px auto; } ul li { list-style: none; } .main li { text-align: center; float: left; padding: 5px; margin-left: 10px; width: 80px; cursor: pointer; background-color: #f3f2e7; } .main .style1 { width: 50px; font-weight: bold; background-color: #f3f2e7; border: 1px solid #837979; border-bottom: 0; z-index: 100; position: relative; } .sublevel { width: 260px; height: 80px; padding: 19px; background-color: #f3f2e7; clear: left; border: 1px solid #837979; position:relative; top: -1px; } .sublevel li{ display: none; } .sublevel .style1{ display: block; }
jquery代碼
$(function () { //頁面打開時 呈現的效果 $(".sublevel li:eq(0)").show(); //each遍歷輸出 $(".main li").each(function(index) { //click 點擊 $(this).click(function() { //addClass()增加當前樣式 removeClass()移除除當前點擊之外的同級樣式 $(this).addClass("main style1").siblings().removeClass("style1"); $(".sublevel li:eq("+index+")").show().siblings().hide(); }) }) })
以上這篇使用jQuery實現簡單的tab框實例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持創新互聯。