原生js写的模态框

HTML代码

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Test</title>
<style>
    #pageMask {
        visibility: hidden;    
        position: absolute;
        left: 0px;    
        top: 0px;
        width:100%;
        height:100%;
        text-align: center;
        z-index: 1100;
        background-color: #333; 
        opacity: 0.6;
    }
    #ModalBody{
        background: white;
        width: 50% !important;
        height: 70% !important;
        height: 70% !important;
        position:absolute;
        left: 25%;
        top: 25%;
        z-index: 1101;
        border: 1px solid;
        display: none;
    }
    #closeOrSaveModalBtn{
        position: static;
        margin-top: 5px;
      margin-right: 1%;
      float: right;
        font-size: 14px;
        background: #ccc0;
        cursor: pointer;
    }
</style>
</head>
<body>
    <div class="content">
        <div id="pageMask"></div>     <!--遮盖层-->
        <button class="showModalBtn" id="showModalBtn">模态框</button>
    </div>
    
    <div id="ModalBody">    <!--模态框-->
       	<div id="responsibilityModel">
       		<div id='rm_title' align="left"><font size="5">负责人信息</font></div>
			<hr/>
			<div style="margin: 10px; " align="left">
				<label for='rm_type' align="left"><font><b>负责人类别</b></font></label><br/>
				<div>
					<select id='rm_type' name="rm_infor" style="width: 100%;">
						<option>1</option>
					</select>
				</div>
				<div>
					<label for='rm_name' align="left"><font><b>负责人姓名</b></font></label><br/>
					<input id='rm_name' type="text" name="rmName" style="width: 100%">
				</div>
				<div>
					<label for='rm_cert_type' align="left"><font><b>证件类型</b></font></label><br/>
					<input id='rm_cert_type' type="text" name="rmCertType" style="width: 100%">
				</div>
				<div>
					<label for='rm_cert_num' align="left"><font><b>证件号码</b></font></label><br/>
					<input id='rm_cert_num' type="text" name="rmCertNum" style="width: 100%">
				</div>
				<div>
					<label for='rm_fixed_telephone' align="left"><font><b>固定电话</b></font></label><br/>
					<input id='rm_fixed_telephone' type="text" name="rmFixedTelephone" style="width: 100%">
				</div>
				<div>
					<label for='rm_mobile_phone' align="left"><font><b>移动电话</b></font></label><br/>
					<input id='rm_mobile_phone' type="text" name="rmMobilePhone" style="width: 100%">
				</div>
				<div>
					<label for='rm_email' align="left"><font><b>电子邮箱</b></font></label><br/>
					<input id='rm_email' type="text" name="rmEmail" style="width: 100%">
				</div>
			</div>
       	</div>
        <div id="closeOrSaveModalBtn">
			<input type="button" id="closeModalBtn" style="display: none;" value="关闭"/>
			<input type="button" id="saveModalBtn" style="display: none;" value="保存"/>
		</div>
		
    </div>
    
    <script>
        window.onload = function(){
            expandIframe();
        }
        function expandIframe(){
            var mask = document.getElementById("pageMask");
            var modal = document.getElementById("ModalBody");
            var closeBtn = document.getElementById("closeModalBtn");
			var saveBtn = document.getElementById("saveModalBtn");
                    var btn = document.getElementById("showModalBtn");
            
            btn.onclick = function(){
                modal.style.display = (modal.style.display == "block")? "none" : "block";
                closeBtn.style.display = (closeBtn.style.display == "inline")? "none" : "inline";
				saveBtn.style.display = (saveBtn.style.display == "inline")? "none" : "inline";
              mask.style.visibility = (mask.style.visibility == "visible")? "hidden" : "visible";
            }
            
            closeBtn.onclick = function(){
                modal.style.display = (modal.style.display == "block")? "none" : "block";
                closeBtn.style.display = (closeBtn.style.display == "inline")? "none" : "inline";
				saveBtn.style.display = (saveBtn.style.display == "inline")? "none" : "inline";
                mask.style.visibility = (mask.style.visibility == "visible")? "hidden" : "visible";
            }
			
			saveBtn.onclick = function(){
				modal.style.display = (modal.style.display == "block")? "none" : "block";
                closeBtn.style.display = (closeBtn.style.display == "inline")? "none" : "inline";
				saveBtn.style.display = (saveBtn.style.display == "inline")? "none" : "inline";
                mask.style.visibility = (mask.style.visibility == "visible")? "hidden" : "visible";
			}
        }
    </script>
</body>
</html>

效果:
在这里插入图片描述

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值