jquery-encapsulated Tab tab plugin sharing _jquery

Source: Internet
Author: User

In the development of the Web site will often use the TAB function, in order to save the time to write code, encapsulating the tab plug-in, easy to invoke.

Create a TAB component

How to use: HTML structure

  <div id= "tabs" >
      <ul>
        <li><a href= "#tabs-1" >tab-1</a></li>
        <li ><a href= "#tabs-2" >tab-2</a></li>
        <li><a href= "#tabs-3" >tab-3</a>< /li>
      </ul>
      <div id= "tabs-1" >tabs-1-panel</div>
      <div id= "Tabs-2" > tabs-2-panel</div>
      <div id= "tabs-3" >tabs-3-panel</div>
 </div>

JS Call

 $ (' #tab '). tabs ();

Related parameter Description:

Initialization parameters

Parameter Default value parameter description
Active NULL sets the index of the selected tab, with a default value of NULL, such as setting the first tab to 0
Event Click Tab switch Events, default to click events, you can set mouseover

Add Tab parameters

Parameter Default value parameter description
Text displayed by the title Empty tab, default to NULL
href Empty tab link, if static data is filled in the corresponding string (#str), the remote data is the corresponding URL
Content blank tab is static data, dynamic data is not required to fill in
ICONCLS true tab Close button, default to display True, False if not displayed

Demo:

Example 1: Static data:

<div id= "tabs" >
      <ul>
        <li><a href= "#tabs-1" >tab-1</a></li>
        <li ><a href= "#tabs-2" >tab-2</a></li>
        <li><a href= "#tabs-3" >tab-3</a>< /li>
      </ul>
      <div id= "tabs-1" >tabs-1-panel</div>
      <div id= "Tabs-2" > tabs-2-panel</div>
      <div id= "tabs-3" >tabs-3-panel</div>
 </div>

JS Call:

 $ (' #tabs '). tabs ();

Example 2: A panel is dynamically created by loading the page with remote data.

<div id= "tabs" >
      <ul>
        <li><a href= "#tabs-1" >tab-1</a></li>
        <li ><a href= "index.jsp" >tab-2</a></li>
        <li><a href= "index.html" >tab-3</a ></li>
      </ul>
      <div id= "tabs-1" >tabs-1-panel</div>
 </div>

JS Call:

 $ (' #tabs '). tabs ();

Example 3: Incoming parameter, setting tab toggle event to MouseOver

<div id= "tabs" >
      <ul>
        <li><a href= "#tabs-1" >tab-1</a></li>
        <li><a href= "index.jsp" >tab-2</a></li>
        <li><a href= "index.html" >tab-3 </a></li>
      </ul>
      <div id= "tabs-1" >tabs-1-panel</div>
 </div>

JS Call:

 $ (' #tabs '). Tabs ({event: ' mouseover '});

Example 4: Add Tab:

<input type= "button" value= "Add Tab" onclick= "AddTab ()" >

<div id= "tabs" >
      <ul>
        <li ><a href= "#tabs-1" >tab-1</a></li>
        <li><a href= "index.jsp" >tab-2</a> </li>
        <li><a href= "index.html" >tab-3</a></li>
      </ul>
      <div id= " Tabs-1 ">tabs-1-panel</div>
 </div>

JS Call:

 $ (' #tabs '). tabs ();
 var tabcount =4;
 function AddTab () {
   tab.tabs (' Add ', {
     title: ' tab-' +tabcount+ ',
     href: ' #tab-' +tabcount+ ',
     Content: ' Tab----' +tabcount+ ',
     iconcls:true
   });
   tabcount++;
 }

Summarize:

Called with different IDs, you can create a different tab structure, with the styles defining different styles by ID.

Little brother. Welcome to the Great God advice ....

Demo Download Address: Myui-tabs

The above mentioned is the entire content of this article, I hope you can enjoy.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.