Home > Web Front-end > JS Tutorial > body text

jquery implements simple Tab switching menu effect

高洛峰
Release: 2017-02-08 16:35:31
Original
1186 people have browsed it

实现tab切换的主要html代码:   

 <p class="container"> 
   
  <ul class="tabs"> 
   <li class="active"><a href="#tab1">导航菜单</a></li> 
   <li><a href="#tab4">TAB标签</a></li> 
  </ul> 
  <p class="tab_container"> 
   <p id="tab1" class="tab_content" style="display: block; "> 
     
    <h3><a href="http://www.freejs.net/article_daohangcaidan_13.html">jquery css多级下拉菜单</a></h3> 
    <p id="">多级菜单,理论上支持无限多的层级,文件结构非常简单的,具体的请看下面的内容</p> 
   </p> 
    
   <p id="tab4" class="tab_content" style="display: none; "> 
    <h2>各种tab标签选项卡</h2> 
    <h3><a href="http://www.freejs.net/article_tabbiaoqian_17.html">tab标签页面,ajax载入</a></h3> 
     
    <p> tab标签,jquery ajax载入数据库的内容</p> 
   </p> 
  </p> 
  
 </p>
Copy after login

实现tab切换的jquery代码:

<script type="text/javascript"> 
 
$(document).ready(function() { 
 
 //默认active 
 $(".tab_content").hide(); //隐藏全部的tab菜单内容
 $("ul.tabs li:first").addClass("active").show(); //对第一个li标签添加class="active属性" 
 $(".tab_content:first").show(); //显示第一个tab内容 
  
 //点击事件 
 $("ul.tabs li").click(function() { 
  $("ul.tabs li").removeClass("active"); //移除class="active"属性
  $(this).addClass("active"); //添加class="active"到选择标签中 
  $(".tab_content").hide(); //隐藏全部标签内容 
  var activeTab = $(this).find("a").attr("href"); //找到所属属性值来识别活跃选项卡和内容 
  $(activeTab).fadeIn(); //使内容消失 
  return false; 
 }); 
 
}); 
</script>
Copy after login

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持PHP中文网。

更多jquery实现简单Tab切换菜单效果相关文章请关注PHP中文网!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!