1

我设法使用 simplemodal 插件让多个模态窗口工作,但我需要能够在它们之间切换而无需用户先手动关闭它。

在这一点上,我仍在通过示例学习这一点。我已经看到了一些关于这个问题的其他参考资料,但是所提供的解决方案要么不起作用,要么没有从相同的构建块开始。

非常感谢任何提示或建议。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SimpleModal</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type='text/javascript' src='js/jquery.simplemodal.js'></script>
<script>
jQuery(function ($) {
    $('#basic-modal .link1').click(function (e) {
        $('#link1-modal-content').modal();
        return false;
    });

    $('#basic-modal .link2').click(function (e) {
        $('#link2-modal-content').modal();
        return false;
    });

    $('#basic-modal .link3').click(function (e) {
        $('#link3-modal-content').modal();
        return false;
    });
});
</script>
<style>
#simplemodal-overlay {background-color:#000; cursor:wait;}
</style>
</head>

<body>

<!-- MAIN PAGE / LINKS TO MODAL WINDOWS-->
<div id='basic-modal'>
    <a href="#" class="link1" id="pop1">Link to Content 1</a><br />
    <a href="#" class="link2" id="pop2">Link to Content 2</a><br />
    <a href="#" class="link3" id="pop3">Link to Content 3</a><br />
</div>



<!-- INDIVIDUAL MODAL WINDOWS CONTENT  -->
<div id="link1-modal-content" style="display:none; width:200px; height:200px; background-color:#FFFFFF;">
    <p>Content 1</p>
    Content 1<br />
    <a href="#" class="link2" id="pop2">Link to Content 2</a><br />
    <a href="#" class="link3" id="pop3">Link to Content 3</a><br />
</div>

<div id="link2-modal-content" style="display:none; width:200px; height:200px; background-color:#FFFFFF;">
    <p>Content 2</p>
    <a href="#" class="link1" id="pop1">Link to Content 1</a><br />
    Content 2<br />
    <a href="#" class="link3" id="pop3">Link to Content 3</a><br />
</div>

<div id="link3-modal-content" style="display:none; width:200px; height:200px; background-color:#FFFFFF;">
    <p>Content 3</p>
    <a href="#" class="link1" id="pop1">Link to Content 1</a><br />
    <a href="#" class="link2" id="pop2">Link to Content 2</a><br />
    Content 3<br />
</div>


</body>
</html>
4

1 回答 1

1

SimpleModal 只允许在任何时候打开一个模态,因此您需要关闭任何现有的模态并打开一个新的模态或交换它们的内容。

要打开/关闭,请使用以下代码代替您的 javascript:

function closeAllModal() {
    $.modal.close();
}

jQuery(function ($) {


    $('.link1').click(function (e) {
        closeAllModal();

        $('#link1-modal-content').modal();
        return false;
    });


    $('.link2').click(function (e) {
        closeAllModal();

        $('#link2-modal-content').modal();
        return false;
    });

    $('.link3').click(function (e) {
        closeAllModal();
        $('#link3-modal-content').modal();

        return false;
    });
});

我已将点击选择器更改为通用的,因此它绑定到所有链接并添加了一个调用以在打开每个模式之前关闭模式。这应该会给你想要的效果。

于 2012-11-05T16:38:03.620 回答