录入信息弹窗及点击空白关闭弹窗的简单组件

简单的弹窗

因为内容比较简单,不做过多的赘述,直接上代码
注:记得引入jquery

<style type="text/css">
	#popWindow {
		position: absolute;
		width: 100%;
		height: 100%;
		top: 0;
		left: 0; 
		/* 增加背景色,提高视觉观感 */
		background-color: rgba(54,54,54,0.5);
		/* 因为是用作展示的,默认显示出来,用的时候需要把注释去掉 */
		/* display: none; */
	}
	.popWinBox {
		position: absolute;
		width: 300px;
		height: 200px;
		top: calc(50% - 100px);
		left: calc(50% - 150px);
		background-color: white;
		text-align: center;
		font-size: 16px;
	}
	.popWinTitle {
		width: 100%;
		height: 30px;
		color: white;
		line-height: 30px;
		background-color: #2A9073;
	}
	.popWinButtonArea {
		width: 100%;
		position: absolute;
		bottom: 0;
		box-sizing: border-box;
		padding: 15px;
	}
	.popWinButton {
		margin: 10px 20px;
	}
	#popTip {
		width: 80%;
		margin: auto;
		color: red;
	}
	</style>
<div id="popWindow">
	<div class="popWinBox" >
		<div class="popWinTitle">弹窗标题</div>
		<p>请录入您想录入的信息</p>
		<input type="text" id="" value="" />
		<p id="popTip"></p> <!-- 用以展示提示信息 -->
		<div class="popWinButtonArea">
			<input type="button" class="popWinButton" id="pftj_button" value="确定" />
			<input type="button" onclick="$('#popWindow').hide();" class="popWinButton" value="取消" />
		</div>
	</div>
</div>

<script type="text/javascript">
	$('#pftj_button').click(function(){
		$('#popTip').html('数据提交中,提交完成会刷新当前页面,请稍后!');
		// $('#popWindow').hide();
		setTimeout(function(){ //定时页面刷新
			window.location.reload();
		},3000)
	});
</script>

点击空白区域关闭弹窗的一种简单实现

这里的实现方式比较简单粗暴,在原有的弹窗页面展示区域,上方加一个masking的div,宽高都设为百分百,不添加背景,然后在点击这个masking的时候关闭显示弹窗
解释:这里利用了两个html或者说css的特性,

  • 1、在不做特别设置的情况下写在下方的dom元素具有更高的层级;
  • 2、点击事件如果加在最外层会具有最高优先级。
<style type="text/css">
	.masking {
		position: absolute;
		width: 100%;
		height: 100%;
	}
</style>

<div id="popWindow">
	<!-- 因为这个click事件比较简单
	就没有再单独在js内写个function出来
	直接这么写也是可以用的 -->
	<div class="masking" onclick="$('#popWindow').hide();"></div>
	<div class="popWinBox" >
		...
	</div>
</div>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值