H+后台框架,实现使用js在TabA中点击按钮打开或刷新TabB页面

需求:后台框架实现使用js在TabA中点击按钮打开或刷新TabB页面

代码示例:

1: 按钮点击事件函数 ajax 实现

            // 点击按钮触发的ajax脚本

            $.ajax({
                url: 按钮调用的后台需处理的其他业务的url地址,
                type: 'get',
                data:{"id":id},
                "dataType": "json",
                async: false,
                success: function (data) {
                   if (data.code !== 0){
                        swal({title: "注意", text: data.message, type: "error"});
                   } else {
                        swal({title: "成功", text: data.message, type: "success"});
                   }
                   page([[@{你的目标tab接口地址}]],"目标tab名称");
                }
            });

2: 打开目标tab的page('你的目标tab接口地址','目标tab名称')实现

function page(url, title) {
        var nav = $(window.parent.document).find('.J_menuTabs .page-tabs-content .J_menuTab');
        if (nav.text().indexOf('目标tab名称')) {
            // 如果目标tab已打开,只做刷新动作
            showTab('目标tab URL');
            refreshHTab('目标tab URL');
        } else {  
            // 如果目标tab未打开,直接打开新tab
            $(window.parent.document).find('.J_menuTabs .page-tabs-content ').find(".J_menuTab.active").removeClass("active");
            $(window.parent.document).find('.J_mainContent').find("iframe").css("display", "none");
            var iframe = '<iframe class="J_iframe" name="iframe10000" width="100%" height="100%" src="' + url + '" frameborder="0" data-id="' + url
                + '" seamless="" style="display: inline;"></iframe>';
            $(window.parent.document).find('.J_menuTabs .page-tabs-content ').append(
                ' <a href="javascript:;" class="J_menuTab active" data-id="'+url+'">' + title + ' <i class="fa fa-times-circle"></i></a >');
            $(window.parent.document).find('.J_mainContent').append(iframe);
        }
    }

    //刷新标签页
    function refreshHTab(data_id){
        var a = (window.top);
        var ele = a.document.querySelectorAll('[data-id="' + data_id + '"]')[1];
        ele.contentWindow.location.reload(true);
    }
    
    // 只把目标tab置为active
    function showTab(dataId){
        $(window.parent.document).find(".J_menuTabs .page-tabs-content .J_menuTab").each(function (i,val) {
            if (val.getAttribute('data-id') == dataId) {
                if (val.getAttribute('class').indexOf('active') < 0) {
                    val.setAttribute('class','J_menuTab active');
                    $(window.parent.document).find(".J_mainContent .J_iframe").each(function (j,content) {
                        if (content.getAttribute('data-id') == dataId) {
                            content.setAttribute('style','display:true');
                        } else {
                            content.setAttribute('style','display:none');
                        }
                    });
                }
            } else {
                if (val.getAttribute('class').indexOf('active') > 0) {
                    val.setAttribute('class','J_menuTab');
                }
            }
        });
    }

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值