Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery EasyUI Layout Plugin - Tabs

jQuery EasyUI Layout Plugin - Tabs


jQuery EasyUI Plugins jQuery EasyUI Plugins


Override the defaults through $.fn.tabs.defaults.

The tabs display a collection of panel. It shows only one tab panel at a time. Each tab panel has the header title and some mini button tools, including close button and other customized buttons.

Depends on

Usage

Creating Tabs

1. Creating Tabs from markup

It is easier to create Tabs from markup, and we don't need to write any JavaScript code. Remember to add the 'easyui-tabs' class to

markup. Each tab panel is created through a child
element, and its usage is the same as that of a panel.



        tab1
        tab2
        tab3

2. Creating Tabs programmatically

Now we create Tabs programmatically, and we also capture the 'onSelect' event.



$('#tt').tabs({

    border:false,

    onSelect:function(title){

        alert(title+' is selected');

    }

});

Adding a New Tab Panel

Add a new tab panel through the mini tool, whose icon (8x8) is placed before the close button.



// Add a new tab panel

$('#tt').tabs('add',{

    title:'New Tab',

    content:'Tab Body',

    closable:true,

    tools:[{

        iconCls:'icon-mini-refresh',

        handler:function(){

            alert('refresh');

        }

    }]

});

Getting the Selected Tab



// Get the selected tab panel and its tab object

var pp = $('#tt').tabs('getSelected');

var tab = pp.panel('options').tab; // 相应的标签页(tab)对象 

property

Name Type Description Default value
width number The width of the Tabs container. auto
height number The height of the Tabs container. auto
plain boolean When set to true, no background container image is used to render the tab strip. false
fit boolean When set to true, the Tabs container is sized to fit its parent container. false
border boolean When set to true, the Tabs container border is shown. true
scrollIncrement number The number of pixels to scroll each time a tab scroll button is pressed. 100
scrollDuration number The number of milliseconds each scrolling animation should last. 400
tools array,selector The toolbar placed on the left or right side of the header. Possible values:
 1、数组,指示工具组,每个工具选项都和链接按钮(Linkbutton)一样。       

 2、选择器,指示包含工具的 
。 Code example: 通过数组定义工具。

$('#tt').tabs({ tools:[{ iconCls:'icon-add', handler:function(){ alert('add') } },{ iconCls:'icon-save', handler:function(){ alert('save') } }] }); Define the tools through an existing DOM container.

$('#tt').tabs({

    tools:'#tab-tools'

});

         
| null| onSelect | event | toolPosition | string | The toolbar position. Possible values: 'left', 'right'. This property is available since version 1.3.2. | right| onSelect | event | tabPosition | string | The tab (tab) position. Possible values: 'top', 'bottom', 'left', 'right'. This property is available since version 1.3.2. | top| onSelect | event | headerWidth | number | The header width of the tab (tab), valid only when tabPosition is set to 'left' or 'right'. This property is available since version 1.3.2. | 150| onSelect | event | tabWidth | number | The width of the tab bar. This property is available since version 1.3.4. | auto| onSelect | event | tabHeight | number | The height of the tab bar. This property is available since version 1.3.4. | 27| onSelect | event | selected | number | The index of the initially selected tab. This property is available since version 1.3.5. | 0| onSelect | event | showHeader | boolean | When set to true, the header of the tab (tab) is shown. This property is available since version 1.3.5. | true |

Events

Name Parameters Description
onLoad panel Fired when an ajax tab panel finishes loading remote data.
onSelect title,index Triggered when the user selects a tab panel (tab panel).
onUnselect title,index Triggered when the user deselects a tab panel (tab panel). This event is available since version 1.3.5.
onBeforeClose title,index Triggered before a tab panel (tab panel) is closed; returning false cancels the closing action. The example below demonstrates how to show a confirmation dialog before closing a tab panel (tab panel).

$('#tt').tabs({ onBeforeClose: function(title){ return confirm('Are you sure you want to close ' + title); } }); // using the async confirm dialog $('#tt').tabs({ onBeforeClose: function(title,index){ var target = this; $.messager.confirm('Confirm','Are you sure you want to close '+title,function(r){ if (r){ var opts = $(target).tabs('options'); var bc = opts.onBeforeClose; opts.onBeforeClose = function(){}; // allowed to close now $(target).tabs('close',index); opts.onBeforeClose = bc; // restore the event function } }); return false; // prevent from closing } });| onSelect | event | onClose | title,index | Triggered when the user closes a tab panel (tab panel).| onSelect | event | onAdd | title,index | Triggered when a new tab panel (tab panel) is added.| onSelect | event | onUpdate | title,index | Triggered when a tab panel (tab panel) is updated.| onSelect | event | onContextMenu | e, title,index | Triggered when a tab panel (tab panel) is right-clicked. |

Method

Name Parameters Description
options none Return the tabs (tabs) options (options).
tabs none Return all tab panels (tab panel).
resize none Resize the tabs (tabs) container and lay it out.
add options Adds a new tab panel. The options parameter is a configuration object; for more details, see the tab panel properties.
 当添加一个新ofLabel页面板(tab panel)时,它将被选in.       

 如需添加一个未选中ofLabel页面板(tab panel),请记得设置 'selected' 属性为 false。     

// add a unselected tab panel $('#tt').tabs('add',{ title: 'new tab', selected: false //... });| onSelect | event | close | which | Closes a tab panel. The 'which' parameter can be the title or the index of the tab panel to be closed.| onSelect | event | getTab | which | Gets the specified tab panel. The 'which' parameter can be the title or the index of the tab panel.| onSelect | event | getTabIndex | tab | Gets the index of the specified tab panel.| onSelect | event | getSelected | none | Gets the selected tab panel. The following example shows how to get the index of the selected tab panel.

var tab = $('#tt').tabs('getSelected');

var index = $('#tt').tabs('getTabIndex',tab);

alert(index);

| onSelect | event | select | which | Selects a tab panel. The 'which' parameter can be the title or the index of the tab panel.| onSelect | event | unselect | which | Unselects a tab panel. The 'which' parameter can be the title or the index of the tab panel. This method is available since version 1.3.5.| onSelect | event | showHeader | none | Shows the tabs header. This method is available since version 1.3.5.| onSelect | event | hideHeader | none | Hides the tabs header. This method is available since version 1.3.5.| onSelect | event | exists | which | Indicates whether the specified panel already exists. The 'which' parameter can be the title or the index of the tab panel.| onSelect | event | update | param | Updates the specified tab panel. The param parameter contains two properties:
tab: the tab panel to be updated.
options: the options of the panel.

 代码实例:     

// update the selected panel with new title and content var tab = $('#tt').tabs('getSelected'); // get selected panel $('#tt').tabs('update', {     tab: tab,     options: {         title: 'New Title',         href: 'get_content.php' // the new content URL     } });

// call 'refresh' method for tab panel to update its content var tab = $('#tt').tabs('getSelected'); // get selected panel tab.panel('refresh', 'get_content.php');| onSelect | event | enableTab | which | Enables the specified tab panel. The 'which' parameter can be the title or index of the tab panel. This method is available since version 1.3.

 代码实例:     

$('#tt').tabs('enableTab', 1); // enable the second tab panel. $('#tt').tabs('enableTab', 'Tab2'); // enable the tab panel whose title is 'Tab2'. onSelect is an event, and disableTab is a method that takes a which parameter. Enable the specified tab panel; the 'which' parameter can be the title or index of the tab panel. This method has been available since version 1.3.

 代码实例:     

$('#tt').tabs('disableTab', 1); // disable the second tab panel.| onSelect | event | scrollBy | deltaX | Scroll the header of the tab (tab) by the specified number of pixels. A negative value scrolls to the right, a positive value scrolls to the left. This method is available since version 1.3.2.

 代码实例:     

// scroll the tab header to left $('#tt').tabs('scroll', 10); |

Tab Panel (Tab Panel)

The tab panel (tab panel) properties are defined in the panel (panel) component; below are some commonly used properties.

Name Type Description Default value
id string The id property of the tab panel (tab panel). null
title string The title text of the tab panel (tab panel).
content string The content of the tab panel (tab panel).
href string The URL for loading remote content to fill the tab panel (tab panel). null
cache boolean When set to true, this tab panel (tab panel) is cached when a valid href attribute is set. true
iconCls string The CSS class of the icon displayed on the title of the tab panel (tab panel). null
width number The width of the tab panel (tab panel). auto
height number The height of the tab panel (tab panel). auto
collapsible boolean When set to true, the tab panel (tab panel) is allowed to be collapsible. false

Some additional properties.

Name Type Description Default value
closable boolean When set to true, the tab panel (tab panel) will show a close button; clicking it closes this tab panel (tab panel). false
selected boolean When set to true, the tab panel (tab panel) will be selected. false

jQuery EasyUI Plugins jQuery EasyUI Plugins