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

效果图:

相关推荐
南部余额几秒前
playwright解决重复登录问题,通过pytest夹具自动读取storage_state用户状态信息
前端·爬虫·python·ui·pytest·pylawright
前端与小赵11 分钟前
webpack和vite之间的区别
前端·webpack·vite
zy01010114 分钟前
React受控表单绑定
前端·javascript·react.js·mvvm·双向数据绑定
百锦再15 分钟前
React编程的核心概念:数据流与观察者模式
前端·javascript·vue.js·观察者模式·react.js·前端框架·ecmascript
2401_8724878816 分钟前
网络安全之前端学习(css篇2)
前端·css·学习
SuperYing27 分钟前
前端候选人突围指南:让面试官主动追着要简历的五大特质(个人总结版)
前端·面试
前端双越老师30 分钟前
我的编程经验与认知
前端
linweidong36 分钟前
前端Three.js面试题及参考答案
前端·javascript·vue.js·typescript·前端框架·three.js·前端面经
GISer_Jing1 小时前
前端常问的宏观“大”问题详解(二)
linux·前端·ubuntu
Moment1 小时前
前端性能指标 —— CLS
前端·javascript·面试