我們在使用easyui的tab時,有時候需要每次點選tab頭,動态重新整理該tab下的iframe的内容
tab的html如下:
Html代碼:
div id="tab-user-right" >
<div title="直接配置設定的操作權限" id="user-right-act">
<iframe scrolling="yes" frameborder="0" height="500" width="100%" frameborder="0" ></iframe>
</div>
<div title="擁有的角色" id="user-role">
<iframe scrolling="yes" frameborder="0" height="500" width="100%" frameborder="0" ></iframe>
</div>
<div title="繼承自角色的權限" id="user-right-role">
<iframe scrolling="yes" frameborder="0" height="500" width="100%" frameborder="0" ></iframe>
</div>
<div title="全部操作權限" id="user-right-all">
<iframe scrolling="yes" frameborder="0" height="500" width="100%" frameborder="0" ></iframe>
</div>
<div title="資料權限-機構" id="user-right-org">
<iframe scrolling="yes" frameborder="0" height="500" width="100%" frameborder="0" ></iframe>
</div>
<div title="資料權限-部門" id="user-right-dept">
<iframe scrolling="yes" frameborder="0" height="500" width="100%" frameborder="0" ></iframe>
</div>
</div>
動态重新整理的js如下:
j//标記是否從新重新整理
var reload="T";
$(function(){
$('#tab-user-right').tabs({
onSelect: function(){
openTab();
}
});
});
function openTab(){
var tab = $('#tab-user-right').tabs('getSelected');
var tbId = tab.attr("id");
//擷取tab的iframe對象
var tbIframe = $("#"+tbId+" iframe:first-child");
if(reload=="T"){
tbIframe.attr("src",tbId+'.action?userId='+userId);
}else{
if( tbIframe.attr("src")==""){
tbIframe.attr("src",tbId+'.action?userId='+userId);
}
}
}```
注意一下代碼:
var tab = $('#tab-user-right').tabs('getSelected');
var tbId = tab.attr("id");
//擷取tab的iframe對象
var tbIframe = $("#"+tbId+" iframe:first-child");