当我对这个字段进行聚焦时会出现一个模态框。每当我点击其他地方时它就会消失。
我无法双击以显示过去的值,因为双击时,模式框首先出现然后进行,即第二次单击未注册为单击文本字段。如何在不关闭模态框的情况下双击打开过去值列表?
function edifactTagsInfo() {
document.getElementById('myModal').style.display = "block";
}
function blurEdifactTagsInfo() {
document.getElementById('myModal').style.display = "none";
}
.modal {
display: none;
/* Hidden by default */
position: fixed;
/* Stay in place */
z-index: 0;
/* Sit on top */
padding-top: 100px;
/* Location of the box */
left: 0;
top: 0;
width: 100%;
/* Full width */
height: 100%;
/* Full height */
overflow: auto;
/* Enable scroll if needed */
background-color: red;
/* Fallback color */
background-color: rgba(0, 0, 0, 0);
/* Black w/ opacity */
opacity: 0.9;
filter: alpha(opacity=90);
}
/* Modal Content */
.modal-content {
background-color: #fff;
margin: auto;
padding: 25px;
border: 5px solid #0eaadc;
width: 50%;
font-family: Amadeus_Font, sans-serif;
font-weight: bold;
font-style: normal;
font-size: 20px;
color: #0c65ba;
}
<input type="text" id="edifactTagsField" onfocus="edifactTagsInfo()" onblur="blurEdifactTagsInfo()">
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close"></span>
<p>TEXT</p>
</div>
</div>
答案 0 :(得分:0)
试试这个:
function edifactTagsInfo() {
document.getElementById('myModal').style.display = "block";
}
document.getElementById('edifactTagsField').parentElement.addEventListener('click',function() {
document.getElementById('myModal').style.display = "none";
});
.modal {
display: none;
/* Hidden by default */
position: fixed;
/* Stay in place */
z-index: 0;
/* Sit on top */
padding-top: 100px;
/* Location of the box */
left: 0;
top: 0;
width: 100%;
/* Full width */
height: 100%;
/* Full height */
overflow: auto;
/* Enable scroll if needed */
background-color: red;
/* Fallback color */
background-color: rgba(0, 0, 0, 0);
/* Black w/ opacity */
opacity: 0.9;
filter: alpha(opacity=90);
}
/* Modal Content */
.modal-content {
background-color: #fff;
margin: auto;
padding: 25px;
border: 5px solid #0eaadc;
width: 50%;
font-family: Amadeus_Font, sans-serif;
font-weight: bold;
font-style: normal;
font-size: 20px;
color: #0c65ba;
}
<input type="text" id="edifactTagsField" onfocus="edifactTagsInfo()">
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close"></span>
<p>TEXT</p>
</div>
</div>
我所做的就是删除隐藏 edifactTagsField 的模态 onBlur 事件,并向父级添加 onClick 侦听器 of edifactTagsField 隐藏模态;