layui从子iframe打开父iframe的tab选项卡

数据表格字段:
{field: 'novelId', title: '小说ID',width:100,templet: ''}
 
function showChapters(obj,param) {
        layui.use(['element'], function () {
            $ = layui.jquery;
            element = layui.element;
           var novelName=$(obj).attr("novelName");
            var url=$(obj).attr("_href")+"?param="+param; //携带小说id,展示该小说下的全部章节
            for (var i = 0; i <$('.x-iframe', window.parent.document).length; i++) { //获取父页面的dom元素
                if($('.x-iframe',window.parent.document).eq(i).attr('data-id')==param){
                    parent.element.tabChange('x-tab', i);
//x-tab 为父页面
                    return;
                }
            };
            res = parent.element.tabAdd('x-tab', { //从父页面添加tab选项卡,如果不指定id,选项卡id会自增
                title: novelName //用于演示
                ,content: ''
            });
            parent.element.tabChange('x-tab', $('.layui-tab-title li',window.parent.document).length-1); //添加选项卡后,默认此tab为选中状态
 
            $('.layui-tab-title li',window.parent.document).eq(0).find('i').remove();
 
        });
    }

转载于:https://www.cnblogs.com/dingxu/p/9594195.html

你可能感兴趣的:(javascript,ViewUI)