简体   繁体   English

jQuery弹出关闭按钮不起作用

[英]jQuery popup close button dont work

I have a problem with the jQuery dialog popup. 我的jQuery对话框弹出窗口有问题。 Here's the code: 这是代码:

<a href="#popup_open" class="btn sign-up popup wow fadeInLeft" data-wow-delay="0.4s">CLICK TO OPEN</a>
<div id="popup_open" style="display:none">
    <div class="dialog">
        POPUP CONTENT
        <div class="popup_close">×</div>
    </div>
</div>

and the js: 和js:

$('a.popup').popup();

I wrote a simple closing script, but it only works one time. 我写了一个简单的结束脚本,但是只能使用一次。

$(document).ready(function () {
    $('.popup_close').click(function () {
        $('.popup_back').css('opacity', '0');
        $('.popup_cont').css('opacity', '0');
    });
});

How do I make the popup close every time? 如何每次关闭弹出窗口?

One solution (though maybe not the best) is to add that click event on the close button in the function that opens the popup. 一种解决方案(尽管可能不是最好的)是在打开弹出窗口的函数中的关闭按钮上添加该click事件。 If you go into developer tools and manually add the click event to the close button after the modal is open, it works every time. 如果您进入开发人员工具并在模式打开后手动将click事件添加到关闭按钮,则每次都会起作用。

Something like this could work: 这样的事情可能会起作用:

$(".popup").click(function() { // Put the correct selector here, this is just a guess

    // Opens the popup
    $('a.popup').popup();

    // Binds the click function
    $('.popup_close').click(function () {
        $('.popup_back').css('opacity', '0');
        $('.popup_cont').css('opacity', '0');
    });
});

There may be a cleaner solution but this is quick and dirty. 可能有一个更清洁的解决方案,但这既快速又肮脏。

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

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