gpt4 book ai didi

javascript - 模态窗口 : How can I set a different content for each modal?

转载 作者:行者123 更新时间:2023-11-30 16:48:55 26 4
gpt4 key购买 nike

我正在处理我自己的自定义模式窗口,但我遇到了问题。我想创建多个模态窗口,但我需要为每个窗口应用不同的内容。

我的 HTML 代码:

        <div id="footer">
<div class="wrapper">
<ul>
<li>
<a class="modal-window-trigger" id="help" href="help.php">Help</a>
</li>
<li>
<a class="modal-window-trigger" id="faq" href="faq.php">Frequently Asked Questions</a>
</li>
</ul>
<span id="footer-copyright">
<a href="./..">Coded by Dylan - ©2015-2016</a>
</span>
</div>
</div>
<div class="modal-window">
<div class="modal-window-container">
<span class="modal-window-closer" title="Close the overlay"></span>
<h1 class="big-title" style="margin-bottom: 15px;">First Modal Window</h1>
<p>First Modal Window Text</p>
</div>
</div>
<div class="modal-window">
<div class="modal-window-container">
<span class="modal-window-closer" title="Close the overlay"></span>
<h1 class="big-title" style="margin-bottom: 15px;">Second Modal Window</h1>
<p>Second Modal Window Text</p>
</div>
</div>
<div id="expose-mask"></div>

我的 JavaScript 代码:

(function($)
{
$(".modal-window-trigger").click(function(e)
{
e.preventDefault();
$(".modal-window").addClass("shown");
$("#expose-mask").css({"visibility": "visible"});
});
$(".modal-window-closer, #expose-mask").click(function(){
$("#expose-mask").css({"visibility": "hidden"});
$(".modal-window").removeClass("shown");
});
})(jQuery);

结果:http://prntscr.com/7gd7g6

我想在点击“帮助”文本时显示具体内容,在点击“常见问题”文本时显示其他内容。

如何为每个模态设置唯一的数据?

最佳答案

    (function($)
{
$(".modal-window-trigger").click(function(e)
{
e.preventDefault();
var modal_id = $(this).attr('name');
show_modal(modal_id)

});
$(".modal-window-closer, #expose-mask").click(function(){
$("#expose-mask").css({"visibility": "hidden"});
$(".modal-window").removeClass("shown");
});
})(jQuery);

function show_modal(modal_id){
$('#'+modal_id).addClass("shown");
$("#expose-mask").css({"visibility": "visible"});
}

<a class="modal-window-trigger" name="model1"> 添加名称属性并将 modal-window 的 id 分别更改为 model1。

关于javascript - 模态窗口 : How can I set a different content for each modal?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30815037/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com