[英]Load modal on click
I want to load modal automatically on page load and the modal would close and reopen onclick.我想在页面加载时自动加载模态,并且模态将关闭并重新打开 onclick。 I have put following command to automatically load modal
modal.open();
我已经输入了以下命令来自动加载模态
modal.open();
This loaded my modal automatically on page load.这会在页面加载时自动加载我的模式。 Later I have used following to close the modal on button click:
function onClick() { if (modal.isOpen) {close(); } }
后来我使用以下方法关闭按钮单击时的模式:
function onClick() { if (modal.isOpen) {close(); } }
function onClick() { if (modal.isOpen) {close(); } }
This one is working too. function onClick() { if (modal.isOpen) {close(); } }
这个也可以。 But now, I want to load the modal again by clicking the button which is not working.但是现在,我想通过单击不起作用的按钮再次加载模式。 When I am placing
openButton.addEventListener("click", function() { modal.open(); });
当我放置
openButton.addEventListener("click", function() { modal.open(); });
instead of modal.open();
而不是
modal.open();
the modal is loading on every alternative click and closing on other clicks.模式在每次替代点击时加载并在其他点击时关闭。 But in this scenario, I am not getting automatically loading of modal on page load.
但在这种情况下,我不会在页面加载时自动加载模式。
I'll try to answer the best I can without seeing your functions.在没有看到您的功能的情况下,我会尽力回答。
function onClick() {
if(modal.isOpen) {
close();
} else {
modal.open(); // you just need to call the same function you called when opening the page.
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.