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

jQuery is the simplest implementation of tab option switching

php中世界最好的语言
Release: 2018-04-26 09:40:18
Original
3130 people have browsed it

This time I will bring you the simplest implementation of tab option switching in jQuery. What are the precautions for jQuery to implement tab option switching. The following is a practical case, let's take a look.

Rendering:

jQuery is the simplest implementation of tab option switching

Code:

nbsp;html>


<meta>
<script></script>
<title>简单的tab效果</title>
<style>
* {
  padding: 0px;
  margin:0px
}
body {
  text-align: center
}
.wrap ul {
  overflow: hidden
}
.wrap li {
  float: left;
  list-style: none;
  margin-right: 10px;
  cursor: pointer;
  padding: 2px 5px
}
.link {
  cursor: pointer;
  color: #F00
}
.wrap {
  width: 200px;
  margin: 50px auto
}
.wrap, .ellipsis {
  font-size: 12px;
  width: 200px;
}
.tab_p p {
  display: none;
  padding: 10px;
}
.tab_p {
  text-align: left;
  border: 1px #CCC solid;
  height: 200px;
  clear: both
}
.cur {
  background: #060;
  color: #FFF
}
#setTab_2{
  margin-top: 20px;
}
</style>
<script>
$(document).ready(function() {
  //tab
    $("#setTab").setTab();
    $("#setTab_2").setTab();
});
 
/*插件代码*/
(function ($) {
  $.fn.setTab = function () {
    var getTab=$(this),//this指向调用函数的ID
      panels = getTab.children("p.tab_p").children("p"),
      tabs = getTab.find("li");
 
    return this.each(function(){
      $(tabs).click(function(e) {
        var index = $.inArray(this, $(this).parent().find("li"));//this指向li
        if (panels.eq(index)[0]) {
          $(tabs).removeClass("cur");
          $(this).addClass("cur");
          panels.css("display", "none").eq(index).css("display", "block");
        }
      });
       
    });
 }
})(jQuery);
 
 
</script>


<p>
 </p>
Copy after login
      
  • 国事
  •   
  • 军情
  •   
  • 图片
  •  
 

  

国事

  

军情

  

图片

 

 

      
  • 国事
  •   
  • 军情
  •   
  • 图片
  •  
 

  

国事

  

军情

  

图片

 

I believe I read the case in this article You have mastered the method. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

jquery implements element drag sorting (with code)

jQuery CSS implements label column switching (With code)

The above is the detailed content of jQuery is the simplest implementation of tab option switching. For more information, please follow other related articles on the PHP Chinese website!

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!