我试图从菜单中的不同按钮打开此弹出窗口,但是,弹出窗口内容将保持不变。
Thanks, Banick
function OpenModalT() {
var modal = document.getElementById('myModalT');
modal.style.display = "block";
}
function CloseModalT() {
var modal = document.getElementById('myModalT');
modal.style.display = "none";
}
<li>
<a href="#" onclick="OpenModalT();">Button 1</a>
<div id="myModalT" class="modal">
<div class="modal-content">
<span class="close" onclick="CloseModalT();">×</span>
<p>
<ppopup>
<br>
<br>
<strong>Dummy text Dummy text Dummy Text <br><br> Kind Regards
</strong>
</ppopup>
</p>
</div>
</div>
</li>
<li>
<a href="#" onclick="OpenModalT();">Button 2</a>
</li>
这是一个可以拥有任意数量的模态框和按钮的示例:
- 使用具有唯一 ID 的模态
- Use
<button type="button" data-modal="#some-modal-id">
切换你的模式
const elsModals = document.querySelectorAll(".modal");
const toggleModal = (ev) => {
const elBtn = ev.currentTarget;
const elModal = document.querySelector(elBtn.dataset.modal);
// Close all currently open modals:
elsModals.forEach(el => {
if (el !== elModal) el.classList.remove("is-active");
});
// Toggle open/close targeted one:
elModal.classList.toggle("is-active");
};
const elsBtns = document.querySelectorAll("[data-modal]");
elsBtns.forEach(el => el.addEventListener("click", toggleModal));
/*QuickReset*/ * {margin:0; box-sizing: border-box;}
.modal {
position: fixed;
z-index: 99999;
display: flex;
justify-content: center;
align-items: center;
left: 0; top: 0;
width: 100vw; height: 100vh;
transition: 0.4s;
backdrop-filter: blur(3px);
background: rgba(0,0,0,0.1);
pointer-events: none;
visibility: hidden;
opacity: 0;
}
.modal.is-active {
pointer-events: auto;
visibility: visible;
opacity: 1;
}
.modal-content {
position: relative;
background: #fff;
padding: 30px;
box-shadow: 0 5px 20px -5px rgba(0,0,0,0.3);
}
.modal-close {
position: absolute;
top: 10px;
right: 10px;
}
<div id="modal-regards" class="modal">
<div class="modal-content">
<button type="button" data-modal="#modal-regards" class="modal-close">×</button>
<p>Dummy text Dummy text Dummy Text<br>Kind Regards</p>
</div>
</div>
<div id="modal-help" class="modal">
<div class="modal-content">
<button type="button" data-modal="#modal-help" class="modal-close">×</button>
<p>If something is not clear,<br>feel free to ask.</p>
</div>
</div>
<button type="button" data-modal="#modal-regards">Kind regards</button>
<button type="button" data-modal="#modal-regards">Kind regards</button>
<button type="button" data-modal="#modal-help">Ask for help!</button>
此外:
- 避免使用内联 on* 处理程序,就像您希望不使用内联样式属性一样 - JS 和 CSS 应该只在一个地方 - 这就是您的文件或标签。
- 使用更好的代码编辑器。
”
不太一样"
- 这样的编辑器将标记并突出显示那些小错别字。
-
<ppopup>
是无效的 HTML5 标记。 – Roko C. Buljan 16 分钟前
- 不要使用
<a href="#">
如果你需要一个按钮。使用<button type="button">
反而。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)