cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <h2>jquery自定义插件-tabs</h2>
<ul id="tabs">
<li data-tab="users">Users</li>
<li data-tab="groups">Groups</li>
</ul>
<div id="tabsContent">
<div data-tab="users"> UsersContent... </div>
<div data-tab="groups"> GroupsContent... </div>
</div>
            
          
!
            
              #tabs{
	overflow:hidden;
   margin:0 0;
}
#tabs li{
  list-style-type:none;
  float:left;
  padding:5px 10px;
  border:1px solid #aaa;
  border-bottom:none;
  margin:0px 2px 0px 0px;
  cursor:pointer;
}
#tabs li:hover{
  background:#fafafa;
}
#tabs li.active{
  background:#eeeeee;
}
#tabsContent{
  width:400px;
  height:200px;
  border:1px solid #aaa;
}
#tabsContent div{
  display:none;
  padding:10px 10px;
}
#tabsContent div.active{
  display:block;
}

            
          
!
            
              $.fn.tabs = function (control) {
var element = $(this);
control = $(control);
element.delegate("li", "click", function () {
// 遍历选项卡名称
var tabName = $(this).attr("data-tab");
// 在点击选项卡时触发自定义事件
element.trigger("change.tabs", tabName);
});
// 绑定到自定义事件
element.bind("change.tabs", function (e, tabName) {
element.find("li").removeClass("active");
element.find(">[data-tab='" + tabName + "']").addClass("active");
});
element.bind("change.tabs", function (e, tabName) {
control.find(">[data-tab]").removeClass("active");
control.find(">[data-tab='" + tabName + "']").addClass("active");
});
// 激活第1 个选项卡
var firstName = element.find("li:first").attr("data-tab");
element.trigger("change.tabs", firstName);
return this;
};

//how to use
$(document).ready(function(){
  $("#tabs").tabs("#tabsContent");
});



            
          
!
999px
Loading ..................

Console