最近遇到一個easyui頁籤的問題,當我們打開新的Tab 時,往往要第一個Tab的js是好的,其他的Tab都沒有反應,在這裡我發現$(’#id’).click(function(){})無效,function 函數名(){}是可以用的,但由于多個html檔案中會存在相同的id或者name,還是會導緻沖突
連結:EasyUI頁籤
tab頁籤有兩種建立方式
1、href 以html片段的方式加載到頁面中,預設隻會加載body标簽裡的内容
var title = '權限劃分';
var url = '{{ url_for('authority') }}';
# 判斷路徑是否存在
if ($('#tt').tabs('exists', title)){
$('#tt').tabs('select', title);
# 選中 并重新整理
var tab = $('#tt').tabs('getSelected'); // get selected panel
tab.panel('refresh', url);
} else {
# 新增
$('#tt').tabs('add',{
title:title,
href:url,
closable:true # true時有關閉的按鈕
});
}
2、content 以iframe形式加載到頁面中,加載過程中,需要渲染,時間比href方式長(我現在采用的方式)
if ($('#tt').tabs('exists', title)){
$('#tt').tabs('select', title);
# 選中父級頁籤 直接使用$('#id')無效 并重新整理
var jq = top.jQuery;
var tab = jq('#tt').tabs('getSelected'); // get selected panel
jq('#tt').tabs('update',{
tab: tab,
options: {
content : '<iframe frame scrolling="auto" style="width:100%;height:100%" src="'+url+'"></iframe>',
}});
} else {
# 新增
$('#tt').tabs('add',{
title:title,
href:url,
closable:true # true時有關閉的按鈕
});
}
利用content 和iframe加載可能會出現無法選擇父級頁籤,方法如上面,直接使用$(’#id’)無效
–
iframe 的優點是js互不沖突,可以互相調用
使用iframe 可能會遇到iframe内容不能完全顯示的問題,可以使用下面的js
注意:這個js要放在iframe的外面(父類标簽)才會生效
function provider_reinitIframe() {
var iframe = document.getElementById("provider_urlIframe");
try
{
var bHeight = iframe.contentWindow.document.body.scrollHeight;
/*
var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
var height = Math.max(bHeight, dHeight);
iframe.height = height; */
iframe.height = bHeight;
}
catch (ex) { }
}
iframe 需要的設定(style屬性中不能設定height)
<iframe frame scrolling="auto" id="provider_urlIframe" style="width:100%" src="'+url+'" onload="provider_reinitIframe()"></iframe>