简体   繁体   English

JS代码链接到模式弹出窗口上的“关闭”按钮

[英]JS code linked to a “close” button on a modal popup

Unfortunately I cannot post a working code/example because it's part of a huge HTML template and I cannot extract only the interesting part :( sorry for that. 不幸的是,我无法发布有效的代码/示例,因为它是巨大的HTML模板的一部分,并且我无法仅提取有趣的部分:(抱歉。

Anyway, I have this popup that I define like this: 无论如何,我有这样定义的弹出窗口:

<a id='bookShopping' class="popup-text" href="#book-shopping-dialog"></a>
<div id="book-shopping-dialog" class="mfp-dialog mfp-hide">
    random popup text...
    <button>Close the popup!!!</button>
</div>

and that I call with 我打电话给

<a onclick="document.getElementById('bookShopping').click(); return false;" >PopUp!</a>

The popup itself has a "X" close button on the upper right corner, defined with 弹出窗口本身在右上角有一个“ X”关闭按钮,定义为

<button class="mfp-close">X</button>

I want MY BUTTON, inside the "random text", to be able to close the popup as well. 我希望“随机文本”中的“我的按钮”也能够关闭弹出窗口。 I tried: 我试过了:

1) Give my button the mfp-close class. 1)给我的按钮mfp-close类。
NOPE . 没有 My button will jump to the upper right corner 我的按钮将跳到右上角

2) Setting the div to display:none and/or display:block 2)将div设置为display:none和/或display:block
NOPE . 没有 The popup will close but IT WILL NEVER REAPPEAR. 弹出窗口将关闭,但它将永远不会再出现。

So, my last resort would be to call the same code that the "mfp-close" class is calling. 因此,我的最后选择是调用“ mfp-close”类正在调用的相同代码。 My problem is that I can only find the mfp-close class defined in CSS, nothing in JS. 我的问题是我只能在CSS中找到mfp-close类,而在JS中却找不到。 If I try to "inspect" the "X" button, it will not give me any event linked to it, nor any JS associated with its "click". 如果我尝试“检查”“ X”按钮,它将不会给我链接到它的任何事件,也不会给与它的“单击”关联的任何JS。

I know that without the source code is hard to understand, but the general question is: where, in Chrome or Firefox, can I find ALL THE JS CODE EXECUTED when I click on an element? 我知道没有源代码很难理解,但是普遍的问题是:在Chrome或Firefox中,单击元素时可以在哪里找到执行的所有JS代码?

Thank you in advance. 先感谢您。

You appear to be using the Magnific popup jQuery plugin, which has an API including a close() method. 您似乎正在使用Magnific弹出式jQuery插件,该插件的API包含close()方法。 You should call that method rather than try to hack around with classes. 您应该调用该方法,而不要尝试使用类。

http://dimsemenov.com/plugins/magnific-popup/documentation.html http://dimsemenov.com/plugins/magnific-popup/documentation.html

$.magnificPopup.close();

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

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