取到easyui的tab下iframe方法

咱们在使用easyui的tab时,有时候须要每次点击tab头,动态刷新该tab下的iframe的内容html

tab的html以下:ui

Html代码:spa

<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以下:code

//标记是否重新刷新  
        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);  
                }  
            }  
        }

注意一下代码:orm

Js代码htm

  1. var tab = $('#tab-user-right').tabs('getSelected');  对象

  2.             var tbId = tab.attr("id");  继承

  3.             //获取tab的iframe对象  get

  4.             var tbIframe = $("#"+tbId+" iframe:first-child"); iframe

相关文章
相关标签/搜索