简体   繁体   English

无法显示JavaScript弹出窗口

[英]Unable to display JavaScript popup

I'm trying to display a popup using JavaScript, however, the div with class="popup" is the only thing that is currently being displayed. 我正在尝试使用JavaScript显示弹出窗口,但是,当前仅显示class =“ popup”的div。 Both popup and popup2 should be displayed when the user performs an action. 用户执行操作时,应该同时显示popup和popup2。 I'm not sure what I'm doing wrong. 我不确定自己在做什么错。

HTML: HTML:

<div class="popup">
  <span class="popuptext" id="popup"></span>
</div>

<div class="popup2">
    <div class="popup2text" id="popup2"></div>
    <script src="/popup2.js"></script>
</div>

JavaScript: JavaScript:

$(() => {
  $('#enter').on('keypress', function(e) {
    if (e.keyCode == 13) {
      const newTask = $(this).val();
      if (newTask) {

The above section of the javascript can be ignored javascript的以上部分可以忽略

        var popup = document.getElementById("popup");
        popup.classList.toggle("show");
        var popup2 = document.getElementById("popup2");
        popup2.classList.toggle("show");
      }
    }
  });
});

CSS: CSS:

.popup {
  position: relative;
  display: inline-block;
  cursor: pointer;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.popuptext {
  visibility: hidden;
  width: 160px;
  height: 200px;
  background-color: #131313;
  color: #fff;
  opacity: 0.95;
  text-align: center;
  border-radius: 6px;
  padding: 8px 0;
  position: absolute;
  z-index: 1;
  left: 581px;
  top: 180px;
  margin-left: -80px;
}

.popup .show {
  visibility: visible;
  -webkit-animation: fadeIn 0.5s;
  animation: fadeIn 0.5s;
}

@-webkit-keyframes fadeIn {
  from {opacity: 0;} 
  to {opacity: 1;}
}

@keyframes fadeIn {
  from {opacity: 0;}
  to {opacity:1 ;}
}

#popup2 {
  visibility: hidden;
  color: white;
  font-family: 'Quicksand', sans-serif;
  font-size: 50px;
  top: 50px;
  left: 50px;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

#popup2 .show {
  visibility: visible;
  -webkit-animation: fadeIn 0.5s;
  animation: fadeIn 0.5s;
}

Your HTML code is invalid. 您的HTML代码无效。

Change this 改变这个

<div class="popup">
  <span class="popuptext" id="popup"></span>
</div>

<div class="popup2"></div>
    <div class="popup2text" id="popup2"></div>
    <script src="/popup2.js"></script>
</div>

to this 对此

<div class="popup">
  <span class="popuptext" id="popup"></span>
</div>

<div class="popup2">
    <div class="popup2text" id="popup2"></div>
    <script src="/popup2.js"></script>
</div>

I think you should check your css, As it shouldn't be ".popup .show" and "#popup2 .show", instead it should be "#popup.show" and "#popup2.show" . 我认为您应该检查css,因为它不应该是“ .popup .show”和“#popup2 .show”,而应该是“#popup.show”和“#popup2.show” Then I saw you have given css for ".popup" and not for ".popup2", css for "#popup2" but not for "#popup", similarly you have given css for ".popuptext" and not for ".popup2text". 然后我看到您为“ .popup”而不是“ .popup2”指定了css,为“#popup2”而不是“ #popup”指定了css,类似地,您为“ .popuptext”和“ .popup2text”指定了css ”。

Also Can you please ellaborate exact behaviour you want on page. 还可以请您详细说明您想要的页面上的行为。 Before user enter anything and after user enter something. 在用户输入任何内容之前和之后,用户输入一些内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM