DIV+IFrame实现页面弹出窗口

需求:页面点击超链接或者按钮的时候弹出子窗口,子窗口中编写数据提交给父窗口,父子窗口页面不刷新。

思路:

父窗口:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<input type="text" id="message" disabled="disabled">
	<br>
	<a href="javascript:show();"> <font>弹出框</font>
	</a>
	<div id="myDiv" οnclick="cancle(this);"
		style="position: absolute; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.2); z-index: 998">
		<div id="popupDiv" 
			style="position: absolute; width: 80%; height: 80%; background-color: white; position: absolute; left: 50%; top: 50%; margin-left: -40%; margin-top: -20%;">
			<iframe id="myFrame" frameborder="0" src="show.html"
				style="position: absolute; width: 100%; height: 100%; border-radius: 3px;"></iframe>
		</div>
	</div>
</body>
<script type="text/javascript">
	var myDiv = document.getElementById("myDiv");
	function myfun() {
		// 隐藏myDiv
		myDiv.style.display = "none";
	}
	function cancle(obj) {
		obj.style.display = "none";
	}
	function show() {
		myDiv.style.display = "block";
	}
	function get(data) {
		var message = document.getElementById("message");
		message.value = data;
		myDiv.style.display = "none";
	}
	window.onload = myfun;
</script>
</html>
子窗口:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<div id="allDiv">
		<input type="text" id="data" value="默认值"> <input type="button"
			id="send" οnclick="send();" value="传值给父窗口">
		<h1>弹出框</h1>
		<h1>弹出框</h1>
		<h1>弹出框</h1>
		<h1>弹出框</h1>
		<h1>弹出框</h1>
		<h1>弹出框</h1>
		<h1>弹出框</h1>
		<h1>弹出框</h1>
		<h1>弹出框</h1>
		<h1>弹出框</h1>
		<h1>弹出框</h1>
		<h1>弹出框</h1>
		<h1>弹出框</h1>
		<h1>弹出框</h1>
		<h1>弹出框</h1>
		<h1>弹出框</h1>
		<h1>弹出框</h1>
		<h1>弹出框</h1>
		<h1>弹出框</h1>
		<h1>弹出框</h1>
		<h1>弹出框</h1>
		<h1>弹出框</h1>
		<h1>弹出框</h1>
		<h1>弹出框</h1>
		<h1>弹出框</h1>
		<h1>弹出框</h1>
	</div>
</body>
<script type="text/javascript">
	function load() {
		// 设置滚动条 
		var allDiv = document.getElementById("allDiv");
		allDiv.style.overflow = "auto";
	}
	function send() {
		var data = document.getElementById("data").value;
		window.parent.get(data);
	}
	window.onload = load;
</script>
</html>

效果图:

点击外面的区域也可以隐藏。


  • 3
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
DIV+CSS 页面布局,是一种常用的网页布局方式,可以通过DIV元素和CSS样式来实现网页的各种布局效果。下面是一个简单的DIV+CSS页面布局的示例: ``` <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>DIV+CSS页面布局示例</title> <style type="text/css"> /*清除默认样式*/ *{margin:0;padding:0;} /*设置页面背景颜色*/ body{background-color:#F5F5F5;} /*设置容器样式*/ #container{width:980px;margin:0 auto;} /*设置页眉样式*/ #header{height:80px;background-color:#333;color:#FFF;text-align:center;line-height:80px;} /*设置主体内容区样式*/ #content{background-color:#FFF;padding:20px;} /*设置页脚样式*/ #footer{height:50px;background-color:#333;color:#FFF;text-align:center;line-height:50px;} </style> </head> <body> <!--容器--> <div id="container"> <!--页眉--> <div id="header"> <h1>DIV+CSS页面布局示例</h1> </div> <!--主体内容区--> <div id="content"> <p>这是一个DIV+CSS页面布局的示例。</p> </div> <!--页脚--> <div id="footer"> <p>版权所有 © 2021</p> </div> </div> </body> </html> ``` 在上述示例中,我们使用了DIV元素来创建容器、页眉、主体内容区和页脚等元素,并使用CSS样式来设置它们的外观效果。其中,容器元素的宽度为980像素,居中显示;页眉和页脚元素的背景颜色为黑色,文字颜色为白色,高度分别为80像素和50像素,居中显示;主体内容区元素的背景颜色为白色,内边距为20像素。通过这种方式,我们可以灵活地控制网页的布局效果,从而实现各种复杂的网页布局。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值