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:
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>
国事
军情
图片
国事
军情
图片
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!