jQuery EasyUI Layout - Dynamically Adding Tabs
Adding Tabs is very easy with jQuery EasyUI. You only need to call the 'add' method.
In this tutorial, we will use iframes to dynamically add Tabs displayed on a page. When the add button is clicked, a new tab will be added. If the tab already exists, it will be activated.
Step 1: Create Tabs
This html code is very simple; we create Tabs with a tab panel named 'Home'. Note that we do not need to write any js code.
Step 2: Implement the 'addTab' function
function addTab(title, url){
if ($('#tt').tabs('exists', title)){
$('#tt').tabs('select', title);
} else {
var content = '';
$('#tt').tabs('add',{
title:title,
content:content,
closable:true
});
}
}
We use the 'exists' method to determine whether the tab already exists; if it does, we activate the tab. If not, we call the 'add' method to add a new tab panel.