简体   繁体   English

在模态中多次调用JS“ onclick函数”

[英]Calling a JS “onclick function” multiple times within a modal

I am trying to figure out how to use the same function 我试图弄清楚如何使用相同的功能
(closing a modal when clicking out of the modalbox): (从模态框单击时关闭模态):

window.onclick = function(event) {
if (event.target == modalEth) {
    modalEth.style.display = "none";
}

and

window.onclick = function(event) {
if (event.target == modalBtc) {
    modalBtc.style.display = "none";
}

within to different modals. 内在不同的模态。

Right now, only the onclick funktion "modalBtc" works the way it should. 现在,只有onclick功能“ modalBtc”才能正常工作。

I don't have a clue how to bring the first function "modalEth" to life. 我不知道如何将第一个功能“ modalEth”带入生活。

It would be great if someone could help me out with a solution. 如果有人可以帮助我提供解决方案,那就太好了。


HTML (1. ModalEth, 2. ModalBtc) HTML(1. ModalEth,2. ModalBtc)

<div id="myModalEth" class="modalEth">
<div class="modal-contentEth">
<p>some content</p>
</div>
</div>

<div id="myModalBtc" class="modalBtc">
<div class="modal-contentBtc">
<p>some content</p>
</div>
</div>
document.getElementById('myModalEth').addEventListener('click', function(event) {
    this.style.display = "none";
}
document.getElementById('myModalBtc').addEventListener('click', function(event) {
    this.style.display = "none";
}

This hides the modal when the user clicks inside the modal. 当用户在模态内单击时,这会隐藏模态。

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

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