EasyUI Tabs绑定右键

时间:2023-03-10 05:28:34
EasyUI Tabs绑定右键

JS:


            /*为选项卡绑定右键*/
                $("#tabs").tabs({
                    onContextMenu : function(e) {
                        /* 选中当前触发事件的选项卡 */
                        var subtitle = $(this).text();
                        $('#tabs').tabs('select', subtitle);
                        //显示快捷菜单
                        e.preventDefault();
                        //阻止冒泡
                        $('#menu').menu('show', {
                            left : e.pageX,
                            top : e.pageY
                        });
                        return false;
                    }

})


            //刷新
            $("#m-refresh").click(function () {
                var currTab = $('#tabs').tabs('getSelected');    //获取选中的标签项
                var url = $(currTab.panel('options').content).attr('src');    //获取该选项卡中内容标签(iframe)的 src 属性                 
                if (url == null) {
                    /* 重新设置该标签 */
                    $('#tabs').tabs('update', {
                        tab: currTab,
                        options: {
                            content: '<iframe frameborder="0"  src="Tabs/Monitoring/MonitoringOfMapType.aspx" style="height: 100%; width: 100%;" ></iframe>'//如果用herf,容易导致样式与主页面重载,导致页面奔溃.
                        }
                    })
                }
                else {
                    /* 重新设置该标签 */
                    $('#tabs').tabs('update', {
                        tab: currTab,
                        options: {
                            content: '<iframe frameborder="0"  src="' + url + '"  style="height: 100%; width: 100%;" ></iframe>'//如果用herf,容易导致样式与主页面重载,导致页面奔溃.
                        }
                    })
                }
            });
            //关闭所有
            $("#m-closeall").click(function () {
                $(".tabs li").each(function (i, n) {
                    var title = $(n).text();
                    if (title != '主页') {//非主页全部关闭
                        $('#tabs').tabs('close', title);
                    }
                });
            });
            //除当前之外关闭所有
            $("#m-closeother").click(function () {
                var currTab = $('#tabs').tabs('getSelected');
                currTitle = currTab.panel('options').title;
                $(".tabs li").each(function (i, n) {
                    var title = $(n).text();
                    if (currTitle != title && title != '主页') {//除本页和主页以外全部关闭
                        $('#tabs').tabs('close', title);
                    }
                });
            });
            //关闭当前
            $("#m-close").click(function () {
                var currTab = $('#tabs').tabs('getSelected');
                currTitle = currTab.panel('options').title;
                $('#tabs').tabs('close', currTitle);
            });

html:

<%--右键菜单--%>
    <div id="menu" class="easyui-menu" style="width: 150px;">
        <div id="m-refresh" data-options="iconCls:'icon-reload'">
            刷新</div>
        <div class="menu-sep" data-options="iconCls:''">
        </div>
        <div id="m-closeall" data-options="iconCls:''">
            全部关闭</div>
        <div id="m-closeother" data-options="iconCls:''">
            关闭其他</div>
        <div class="menu-sep">
        </div>
        <div id="m-close" data-options="iconCls:'icon-no'">
            关闭</div>
    </div>