数据表格字段:
{field: 'novelId', title: '小说ID',width:100,templet: '<div><a href="javascript:;" _href="/contentManage/content-chapters.html" novelName="{{d.name}}" onclick="showChapters(this,{{d.novelId}});" class="layui-table-link">{{d.novelId}}</a></div>'}
 
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 为父页面<div class="layui-tab layui-tab-card site-demo-title x-main" lay-filter="x-tab" lay-allowclose="true"></div>
                    return;
                }
            };
            res = parent.element.tabAdd('x-tab', {//从父页面添加tab选项卡,如果不指定id,选项卡id会自增
                title: novelName //用于演示
                ,content: '<iframe frameborder="0" data-id="'+param+'" src="'+url+'" class="x-iframe"></iframe>'
            });
            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();
 
        });
    }
 posted on 2018-09-05 20:12  ding-xu  阅读(9752)  评论(0编辑  收藏  举报