简体   繁体   English

添加一个按钮,使用popup.js关闭弹出窗口

[英]Add a button that closes the popup with popup.js

I'm having troubles creating an exit button for the following script. 我在为以下脚本创建退出按钮时遇到麻烦。 I'm using popup.js from http://docs.toddish.co.uk/popup/ . 我正在使用http://docs.toddish.co.uk/popup/中的 popup.js。 It sais that in order to do it we should use popup.close() from inside the object. 它说为了做到这一点,我们应该从对象内部使用popup.close()。 But there are no examples and I can't get it to work. 但是没有示例,我无法使其正常工作。 Does anyone have an idea? 有人有主意吗?

JSFiddle link = http://jsfiddle.net/andrewallen817/bedhhu1o/3/ JSFiddle链接= http://jsfiddle.net/andrewallen817/bedhhu1o/3/

Html: HTML:

<a href=#txt class="popup" >Click here</a>

<div id="txt" style="display:none">
    <h1>This is a title</h1>
    <p>this is some text</p>
    <button>close</button>    

</div>

JS JS

$(function(){
    $('.popup').popup();
});

I fixed it for you by looking at the doc. 我通过查看文档为您修复了该问题。 JSfiddle 的jsfiddle

$(function () {
    $('.popup').popup({
        afterOpen: function () {
            var popup = this;
            $('button').click(function () {
                popup.close();
            });
        }
    });
});

You might want to specify which button you want to give the popup.close() or else every button will have it. 您可能想要指定要提供给popup.close()的按钮,否则每个按钮都会拥有它。

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

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