当模态框在前面时,如何使其他表单元素可单击?

问题描述 投票:0回答:1

当我对焦这个字段时会出现一个模态框。每当我点击其他地方时它就会发生。

我无法双击以显示过去的值,因为双击时,模式框首先出现然后进行,即第二次单击未注册为单击文本字段。如何在不关闭模态框的情况下双击打开过去值列表?

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>
javascript html css
1个回答
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侦听器添加到edifactTagsField的父级以隐藏模态;

© www.soinside.com 2019 - 2024. All rights reserved.