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>
效果: