jQuery EasyUI 佈局– 動態添加標籤頁(Tabs)
通過使用jQuery EasyUI 可以很容易地添加Tabs。 您只需要調用'add' 方法即可。
在本教程中,我們將使用iframe 動態地添加顯示在一個頁面上的Tabs。 當點擊添加按鈕,一個新的tab 將被添加。 如果tab 已經存在,它將被激活。
步驟1:創建Tabs
<div style="margin-bottom:10px"> <a href="#" class="easyui-linkbutton" onclick="addTab('google','http://www.google.com')">google</a> <a href="#" class="easyui-linkbutton" onclick="addTab('jquery','http://jquery.com/')">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>
這個html 代碼非常簡單,我們創建了帶有一個名為'Home' 的tab 面板的Tabs。 請注意,我們不需要寫任何的js 代碼。
步驟2:實現'addTab' 函數
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 }); } }
我們使用'exists' 方法來判斷tab 是否已經存在,如果已存在則激活tab。 如果不存在則調用'add' 方法來添加一個新的tab 面板。