关闭按钮在弹出窗口上不起作用

时间:2020-08-17 04:11:46

标签: javascript html jquery css

我已经在Google上搜索了一个弹出窗口。我对Web开发没有太多的了解。通过准备并尝试多个网站页面,我为我的网站做了一个模态。我已根据需要在弹出窗口中设置了所有内容,除关闭按钮外,其他功能均正常运行。

可以请您看看我的以下代码,并指导我如何使关闭按钮起作用吗?

jQuery(document).ready(function() {
  jQuery("#dialog-message").css("display", "block");
  jQuery("#close-btn").click(function() {
    jQuery(this).parents('#dialog-message').hide();
  });
});
@import url('https://fonts.googleapis.com/css?family=Montserrat:400,700');
.exit_popup-sec {
  width: 915px;
  position: relative;
  padding: 0px;
  margin: 0 auto;
}

.exit_popup-sec .exit_popup-content {
  background-color: #fff;
  margin: 0px;
  padding: 34px 62px 60px 62px;
  box-sizing: border-box;
  width: 100%;
  float: left;
  -webkit-box-shadow: 0px 10px 20px 0px rgba(50, 50, 50, 0.52);
  -moz-box-shadow: 0px 10px 20px 0px rgba(50, 50, 50, 0.52);
  box-shadow: 0px 10px 20px 0px rgba(50, 50, 50, 0.52);
}

.exit_popup-sec .exit_popup-content h2 {
  margin: 0px;
  padding: 0px;
  color: #ffff00;
  font-family: 'Montserrat', sans-serif;
  font-size: 28px;
  width: 400px;
  float: left;
}

.exit_popup-sec .exit_popup-content h3 {
  margin: 20px 0 30px 0;
  color: #FFF;
  font-family: 'Montserrat', sans-serif;
  font-size: 18px;
  width: 400px;
  float: left;
  line-height: 26px;
}

.exit_popup-sec .exit_popup-content .getoffer-btn {
  width: 50%;
  padding: 20px 0px;
  margin: 0px;
  clear: both;
  float: left;
  border: 0px;
  font-size: 20px;
  font-family: 'Montserrat', sans-serif;
  font-weight: 700;
  color: #fff;
  -webkit-border-radius: 50px;
  border-radius: 50px;
  text-shadow: 0 2px 2px #000;
  -webkit-box-shadow: 0 5px 10px 0 rgba(0, 0, 0, 0.56);
  box-shadow: 0 5px 10px 0 rgba(0, 0, 0, 0.56);
  background: -moz-linear-gradient(top, #337ab7 1%, #4f4fe8 100%);
  ;
  background: -webkit-linear-gradient(top, #337ab7 1%, #4f4fe8 100%);
  background: linear-gradient(to bottom, #337ab7 1%, #4f4fe8 100%);
  filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ff6c00', endColorstr='#ff0000', GradientType=0);
  cursor: pointer;
}

.exit_popup-sec .exit_popup-content .getoffer-btn:hover {
  background: #ff0000;
}

.exit_popup-sec .exit_popup-content .getoffer-btn:focus {
  outline: none;
}

.popup-graybox {
  position: fixed;
  width: 100%;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 99999;
  align-items: center;
  display: flex;
  box-sizing: border-box;
  overflow: auto;
}

.exit_popup-sec .booknow-popup-clsbtn {
  font-size: 14px;
  line-height: 18px;
  width: 28px;
  height: 28px;
  -webkit-border-radius: 50%;
  border-radius: 50%;
  background: #FFF;
  position: absolute;
  right: -7px;
  top: -14px;
  border: 0px;
  -webkit-box-shadow: 0 0 2px 0 rgba(0, 0, 0, 0.27);
  box-shadow: 0 5px 5px 0 rgba(0, 0, 0, 0.27);
  cursor: pointer;
}

.exit_popup-sec .booknow-popup-clsbtn:hover {
  color: #fff;
  background: #252525;
}

@media only screen and (max-width:815px) {
  .exit_popup-sec {
    width: 95%;
  }
  .exit_popup-sec .exit_popup-content {
    padding: 20px 30px 50px 30px;
  }
  .exit_popup-sec .exit_popup-content h2 {
    font-size: 80px;
  }
  .exit_popup-sec .exit_popup-content h3 {
    width: 350px;
  }
}

@media only screen and (max-width:480px) {
  .exit_popup-sec .exit_popup-content h3 {
    width: 100%;
    box-sizing: border-box;
  }
  .exit_popup-sec .exit_popup-content h2 {
    width: 100%;
    box-sizing: border-box;
  }
  .exit_popup-sec .exit_popup-content h2 {
    font-size: 30px;
  }
  .exit_popup-sec .exit_popup-content h3 {
    font-size: 14px;
    line-height: 30px;
  }
}

.ui-widget-content a {
  color: #72d6d6;
}
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>



  <div id="dialog-message">
    <section class="popup-graybox">
      <div class="exit_popup-sec">
        <div class="exit_popup-content" style="background: #252525 url(https://pakxchange.com/pop-up/webmoney.png) no-repeat right 0;">
          <h2 data-edit="text">Webmoney Account Verification</h2>
          <h3 data-edit="text">We are the only Country Representative of <a href="https://passport.wmtransfer.com/asp/Reglist.asp">Webmoney Payment Network</a> in Pakistan. We verify webmoney users, their documents and issue them Initial &amp; Personal passports. <a href="https://pakxchange.com/sources/payment/NewWMZ.php">READ MORE</a></h3>
          <button class="getoffer-btn" type="submit"><a href="https://passport.wmtransfer.com/asp/certview.asp?wmid=085789787326">Our Certified Webmoney Account</a></button>
          <button class="booknow-popup-clsbtn close-btn close-btn">X</button>
        </div>
      </div>
  </div>
  </section>

1 个答案:

答案 0 :(得分:0)

jQuery(document).ready(function() {
      jQuery("#dialog-message").css("display", "block");
      jQuery("#popup_close_btn").click(function() {
        jQuery(this).parents('#dialog-message').hide();
      });
    });
@import url('https://fonts.googleapis.com/css?family=Montserrat:400,700');
    .exit_popup-sec {
      width: 915px;
      position: relative;
      padding: 0px;
      margin: 0 auto;
    }

    .exit_popup-sec .exit_popup-content {
      background-color: #fff;
      margin: 0px;
      padding: 34px 62px 60px 62px;
      box-sizing: border-box;
      width: 100%;
      float: left;
      -webkit-box-shadow: 0px 10px 20px 0px rgba(50, 50, 50, 0.52);
      -moz-box-shadow: 0px 10px 20px 0px rgba(50, 50, 50, 0.52);
      box-shadow: 0px 10px 20px 0px rgba(50, 50, 50, 0.52);
    }

    .exit_popup-sec .exit_popup-content h2 {
      margin: 0px;
      padding: 0px;
      color: #ffff00;
      font-family: 'Montserrat', sans-serif;
      font-size: 28px;
      width: 400px;
      float: left;
    }

    .exit_popup-sec .exit_popup-content h3 {
      margin: 20px 0 30px 0;
      color: #FFF;
      font-family: 'Montserrat', sans-serif;
      font-size: 18px;
      width: 400px;
      float: left;
      line-height: 26px;
    }

    .exit_popup-sec .exit_popup-content .getoffer-btn {
      width: 50%;
      padding: 20px 0px;
      margin: 0px;
      clear: both;
      float: left;
      border: 0px;
      font-size: 20px;
      font-family: 'Montserrat', sans-serif;
      font-weight: 700;
      color: #fff;
      -webkit-border-radius: 50px;
      border-radius: 50px;
      text-shadow: 0 2px 2px #000;
      -webkit-box-shadow: 0 5px 10px 0 rgba(0, 0, 0, 0.56);
      box-shadow: 0 5px 10px 0 rgba(0, 0, 0, 0.56);
      background: -moz-linear-gradient(top, #337ab7 1%, #4f4fe8 100%);
      ;
      background: -webkit-linear-gradient(top, #337ab7 1%, #4f4fe8 100%);
      background: linear-gradient(to bottom, #337ab7 1%, #4f4fe8 100%);
      filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ff6c00', endColorstr='#ff0000', GradientType=0);
      cursor: pointer;
    }

    .exit_popup-sec .exit_popup-content .getoffer-btn:hover {
      background: #ff0000;
    }

    .exit_popup-sec .exit_popup-content .getoffer-btn:focus {
      outline: none;
    }

    .popup-graybox {
      position: fixed;
      width: 100%;
      top: 0;
      left: 0;
      height: 100vh;
      z-index: 99999;
      align-items: center;
      display: flex;
      box-sizing: border-box;
      overflow: auto;
    }

    .exit_popup-sec .booknow-popup-clsbtn {
      font-size: 14px;
      line-height: 18px;
      width: 28px;
      height: 28px;
      -webkit-border-radius: 50%;
      border-radius: 50%;
      background: #FFF;
      position: absolute;
      right: -7px;
      top: -14px;
      border: 0px;
      -webkit-box-shadow: 0 0 2px 0 rgba(0, 0, 0, 0.27);
      box-shadow: 0 5px 5px 0 rgba(0, 0, 0, 0.27);
      cursor: pointer;
    }

    .exit_popup-sec .booknow-popup-clsbtn:hover {
      color: #fff;
      background: #252525;
    }

    @media only screen and (max-width:815px) {
      .exit_popup-sec {
        width: 95%;
      }
      .exit_popup-sec .exit_popup-content {
        padding: 20px 30px 50px 30px;
      }
      .exit_popup-sec .exit_popup-content h2 {
        font-size: 80px;
      }
      .exit_popup-sec .exit_popup-content h3 {
        width: 350px;
      }
    }

    @media only screen and (max-width:480px) {
      .exit_popup-sec .exit_popup-content h3 {
        width: 100%;
        box-sizing: border-box;
      }
      .exit_popup-sec .exit_popup-content h2 {
        width: 100%;
        box-sizing: border-box;
      }
      .exit_popup-sec .exit_popup-content h2 {
        font-size: 30px;
      }
      .exit_popup-sec .exit_popup-content h3 {
        font-size: 14px;
        line-height: 30px;
      }
    }

    .ui-widget-content a {
      color: #72d6d6;
    }
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
    <link rel="stylesheet" href="/resources/demos/style.css">
    <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>



      <div id="dialog-message">
        <section class="popup-graybox">
          <div class="exit_popup-sec">
            <div class="exit_popup-content" style="background: #252525 url(https://pakxchange.com/pop-up/webmoney.png) no-repeat right 0;">
              <h2 data-edit="text">Webmoney Account Verification</h2>
              <h3 data-edit="text">We are the only Country Representative of <a href="https://passport.wmtransfer.com/asp/Reglist.asp">Webmoney Payment Network</a> in Pakistan. We verify webmoney users, their documents and issue them Initial &amp; Personal passports. <a href="https://pakxchange.com/sources/payment/NewWMZ.php">READ MORE</a></h3>
              <button class="getoffer-btn" type="submit"><a href="https://passport.wmtransfer.com/asp/certview.asp?wmid=085789787326">Our Certified Webmoney Account</a></button>
              <button class="booknow-popup-clsbtn close-btn close-btn" id="popup_close_btn">X</button>
            </div>
          </div>
      </div>
      </section>

您通过id引用关闭按钮,并且尚未为关闭按钮分配任何id。请指定ID以关闭按钮。应该可以。

如果要使用CSS选择器方法来解决此问题,请执行以下操作: $(“。booknow-popup-clsbtn”)。