默认情况下禁止打开模式内容



如何让里面的内容在点击之前不打开?每当我制作模式或下拉列表菜单时,默认情况下,它总是在单击之前打开内容。为什么?

var modal = document.getElementById('modal-wrap');
var open = document.getElementById('modal-open');
var close = document.getElementById('modal-close');

open.onclick = function() {
modal.style.display = "block";
};

close.onclick = function() {
modal.style.display = "none";
};
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
.modal-wrap {
display: none;
position: fixed;
z-index: 99;
padding-top: 100px;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
opacity: 40%;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0,0.4); 
}
.modal-content {
background-color: #fefefe;
margin: auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
}
.modal-close {
float: right;
padding: 5px;
border-radius: 5px;
font-weight: bold;
}
.modal-close:hover,
.modal-close:focus {
color: #000;
text-decoration: none;
cursor: pointer;
}
<button id="modal-open">Open</button>
<div id="modal-wrap" class="modal-wrap">
<div class="modal-content">
<button class="modal-close" id="modal-close">Close</button>
<p>Edit the data </p>
<div class="form-group">
<label for="name">Name</label>
<input id="name" placeholder="Input your Name"> 
</div>

</div> 
</div>

而且它在代码段或JS Bin中运行良好(正如预期的那样(。但是,当我在(项目(本地主机上运行它时,为什么默认情况下它的外观会有所不同?此处

我所能想到的可能是你的JavaScript文件链接不正确?

相关内容

最新更新