jQuery EasyUI Layout - dynamically add tabs (Tabs)

Tabs can be added easily by using jQuery EasyUI. You only need to call the 'add' method can be.

In this tutorial, we will use iframe dynamically add Tabs to display on a page. When you click the Add button, a new tab will be added. If the tab already exists, it will be activated.

Step 1: Create Tabs

	<Div style = "margin-bottom: 10px">
		<a href="#" class="easyui-linkbutton" onclick="addTab('google','https://www.google.com.hk/')"> google </a>
		<a href="#" class="easyui-linkbutton" onclick="addTab('jquery','/')"> jquery </a>
		<a href="#" class="easyui-linkbutton" onclick="addTab('easyui','http://jeasyui.com/')"> easyui </a>
	</ Div>
	<Div id = "tt" class = "easyui-tabs" style = "width: 400px; height: 250px;">
		<Div title = "Home">
		</ Div>
	</ Div>

The html code is very simple, we created the Tabs panel with a tab called 'Home''s. Please note that we do not need to write any js code.

Step 2: Implement 'addTab' function

	function addTab (title, url) {
		if ($ ( '# tt'). tabs ( 'exists', title)) {
			$ ( '# Tt') tabs ( 'select', title).;
		} Else {
			var content = '<iframe scrolling = "auto" frameborder = "0" src = "' + url + '" style = "width: 100%; height: 100%;"> </ iframe>';
			$ ( '# Tt'). Tabs ( 'add', {
				title: title,
				content: content,
				closable: true
			});
		}
	}

We use 'exists' method to determine whether the tab already exists, if it exists activated tab. If there is no call to 'add' method to add a new tab panel.

Download jQuery EasyUI examples

jeasyui-layout-tabs2.zip