【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>

效果图:

相关推荐
十八朵郁金香19 分钟前
【JavaScript】深入理解模块化
开发语言·javascript·ecmascript
m0_7482309422 分钟前
Redis 通用命令
前端·redis·bootstrap
YaHuiLiang1 小时前
一切的根本都是前端“娱乐圈化”
前端·javascript·代码规范
菜鸟一枚在这2 小时前
深入解析设计模式之单例模式
开发语言·javascript·单例模式
ObjectX前端实验室2 小时前
个人网站开发记录-引流公众号 & 谷歌分析 & 谷歌广告 & GTM
前端·程序员·开源
CL_IN2 小时前
企业数据集成:实现高效调拨出库自动化
java·前端·自动化
浪九天3 小时前
Vue 不同大版本与 Node.js 版本匹配的详细参数
前端·vue.js·node.js
qianmoQ4 小时前
第五章:工程化实践 - 第三节 - Tailwind CSS 大型项目最佳实践
前端·css
C#Thread4 小时前
C#上位机--流程控制(IF语句)
开发语言·javascript·ecmascript
椰果uu4 小时前
前端八股万文总结——JS+ES6
前端·javascript·es6