【layui】tabs 控件内通过 iframe 加载url 方式渲染tab页面

html 复制代码
<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title>tabs 内部使用 iframe 嵌套 url 页面</title>
	<link rel="stylesheet" href="../../../libs/layui/layui-2.4.5/dist/css/layui.css">
	<script src="../../../libs//layui/layui-2.4.5/dist/layui.js"></script>
	<style>
		/**
		 * iframe 自适应方案
		 */
		.layui-tab-content .layui-show {
			position: fixed;
			width: 100%;
			height: 90%;
			top: 10%;
			left: 0;
		}
	</style>
</head>

<body>


	<div class="layui-fluid weadmin-body">

		<div class="layui-tab layui-tab-brief" lay-filter="tabs">
			<ul class="layui-tab-title">
				<li class="layui-this" lay-id="0">明细</li>
				<li lay-id="1">汇总</li>
			</ul>
			<div class="layui-tab-content">
				<div class="layui-tab-item layui-show" style="">
					<iframe id="iframe_jylc_0" frameborder="0" src="./1.html" scrolling="yes" class="weIframe"
						style="width: 100%;height: 100%;">
					</iframe>
				</div>
				<div class="layui-tab-item ">
					<iframe id="iframe_jylc_1" frameborder="0" src="./2.html" scrolling="yes" class="weIframe"
						style="width: 100%;height: 100%;">
					</iframe>
				</div>
			</div>
		</div>
	</div>
	<script>
		layui.use(['jquery', 'layer', 'form', 'table', 'laydate', 'util', 'upload', 'element'],
			function () {
				var Hussar = layui.Hussar;
				var $ = layui.jquery;
				var layer = layui.layer;
				var form = layui.form;
				var laydate = layui.laydate;
				var $ax = layui.HussarAjax;
				var element = layui.element;
				var table = layui.table;
				var util = layui.util;
				var layerWindow;
				var upload = layui.upload;


				//tabs 点击事件触发
				element.on('tab(tabs)', function (data) {
				    // console.log(data);
				    // console.log($(this)); //当前Tab标题所在的原始DOM元素
				    console.log(data.index); //得到当前Tab的所在下标
				    // console.log(data.elem); //得到当前的Tab大容器
				    // $(data)
				    // console.log($("#iframe_jylc_"+data.index))
				
				});


			})
			;
	</script>
</body>

</html>

内部的 1.html

html 复制代码
<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title>tab1</title>

	<style>
	
	</style>
</head>

<body>
    <div style="width: 100%;height: 100%;border:1px solid green;">
        <span>hello,world!111hello,world!111hello,world!111hello,world!111hello,world!11hello,world!111hello,world!111hello,world!111hello,world!111hello,world!11hello,world!111hello,world!111hello,world!111hello,world!111hello,world!11hello,world!111hello,world!111hello,world!111hello,world!111hello,world!111</span>
        <span>hello,world!111hello,world!111hello,world!111hello,world!111hello,world!11hello,world!111hello,world!111hello,world!111hello,world!111hello,world!11hello,world!111hello,world!111hello,world!111hello,world!111hello,world!11hello,world!111hello,world!111hello,world!111hello,world!111hello,world!111</span>
        <span>hello,world!111hello,world!111hello,world!111hello,world!111hello,world!11hello,world!111hello,world!111hello,world!111hello,world!111hello,world!11hello,world!111hello,world!111hello,world!111hello,world!111hello,world!11hello,world!111hello,world!111hello,world!111hello,world!111hello,world!111</span>
        <span>hello,world!111hello,world!111hello,world!111hello,world!111hello,world!11hello,world!111hello,world!111hello,world!111hello,world!111hello,world!11hello,world!111hello,world!111hello,world!111hello,world!111hello,world!11hello,world!111hello,world!111hello,world!111hello,world!111hello,world!111</span>
        <span>hello,world!111hello,world!111hello,world!111hello,world!111hello,world!11hello,world!111hello,world!111hello,world!111hello,world!111hello,world!11hello,world!111hello,world!111hello,world!111hello,world!111hello,world!11hello,world!111hello,world!111hello,world!111hello,world!111hello,world!111</span>
        <span>hello,world!111hello,world!111hello,world!111hello,world!111hello,world!11hello,world!111hello,world!111hello,world!111hello,world!111hello,world!11hello,world!111hello,world!111hello,world!111hello,world!111hello,world!11hello,world!111hello,world!111hello,world!111hello,world!111hello,world!111</span>
        <span>hello,world!111hello,world!111hello,world!111hello,world!111hello,world!11hello,world!111hello,world!111hello,world!111hello,world!111hello,world!11hello,world!111hello,world!111hello,world!111hello,world!111hello,world!11hello,world!111hello,world!111hello,world!111hello,world!111hello,world!111</span>
        <span>hello,world!111hello,world!111hello,world!111hello,world!111hello,world!11hello,world!111hello,world!111hello,world!111hello,world!111hello,world!11hello,world!111hello,world!111hello,world!111hello,world!111hello,world!11hello,world!111hello,world!111hello,world!111hello,world!111hello,world!111</span>
        <span>hello,world!111hello,world!111hello,world!111hello,world!111hello,world!11hello,world!111hello,world!111hello,world!111hello,world!111hello,world!11hello,world!111hello,world!111hello,world!111hello,world!111hello,world!11hello,world!111hello,world!111hello,world!111hello,world!111hello,world!111</span>
        <span>hello,world!111hello,world!111hello,world!111hello,world!111hello,world!11hello,world!111hello,world!111hello,world!111hello,world!111hello,world!11hello,world!111hello,world!111hello,world!111hello,world!111hello,world!11hello,world!111hello,world!111hello,world!111hello,world!111hello,world!111</span>
        <span>hello,world!111hello,world!111hello,world!111hello,world!111hello,world!111</span>
        <span>hello,world!111hello,world!111hello,world!111hello,world!111hello,world!111</span>
        <span>hello,world!111hello,world!111hello,world!111hello,world!111hello,world!111</span>
        <span>hello,world!111hello,world!111hello,world!111hello,world!111hello,world!111</span>
        <span>hello,world!111hello,world!111hello,world!111hello,world!111hello,world!111</span>
        <span>hello,world!111hello,world!111hello,world!111hello,world!111hello,world!111</span>
        <span>hello,world!111hello,world!111hello,world!111hello,world!111hello,world!111</span>
        <span>hello,world!111hello,world!111hello,world!111hello,world!111hello,world!111</span>
        <span>hello,world!111hello,world!111hello,world!111hello,world!111hello,world!111</span>
        <span>hello,world!111hello,world!111hello,world!111hello,world!111hello,world!111</span>
        <span>hello,world!111hello,world!111hello,world!111hello,world!111hello,world!111</span>
    </div>

	

</body>

</html>

2.html:

html 复制代码
<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title>tab2</title>
</head>

<body>

    <div style="width: 100%;height: 100%;border:1px solid blue;">
        <div>hello,world!222</div>
        <div>hello,world!222</div>
        <div>hello,world!222</div>
        <div>hello,world!222</div>
        <div>hello,world!222</div>
        <div>hello,world!222</div>
        <div>hello,world!222</div>
        <div>hello,world!222</div>
        <div>hello,world!222</div>
        <div>hello,world!222</div>
        <div>hello,world!222</div>
        <div>hello,world!222</div>
        <div>hello,world!222</div>
        <div>hello,world!222</div>
        <div>hello,world!222</div>
        <div>hello,world!222</div>
        <div>hello,world!222</div>
        <div>hello,world!222</div>
        <div>hello,world!222</div>
        <div>hello,world!222</div>
        <div>hello,world!222</div>
        <div>hello,world!222</div>
    </div>
	

</body>

</html>

效果图:

相关推荐
苳烨6 分钟前
UniApp使用最新版Android Studio本地离线打包全流程
前端
Monly219 分钟前
vue报错:Loading chunk * failed,vue-router懒加载出错问题。
前端·javascript·vue.js
李剑一11 分钟前
别再用HTTP/1这个老古董了,两招帮你升级HTTP/2
前端·架构
t20071818 分钟前
4.27 react第一天
前端·react.js·前端框架
飞天牛牛22 分钟前
前端小知识:彻底搞懂 CSS 的 `position: sticky`!
前端
大名人儿33 分钟前
【JS事件循环机制event-loop】
javascript·事件循环·宏任务·微任务·event-loop
vim怎么退出33 分钟前
46.二叉树展开为链表
前端·leetcode
薛定谔的猫240 分钟前
Composition API的深入理解与最佳实践
前端·vue.js
NaN_37242 分钟前
新手教程-使用 Android Studio 搭建 React Native 项目开发环境
前端
天天扭码1 小时前
JavaScript 中 apply 和 call 方法的区别与应用场景
前端·javascript·面试