简单模态 - 如何将电子邮件地址传递给确认模式



我正在尝试使用SimpleModal作为电子邮件免责声明的确认,即单击电子邮件地址弹出模态,同意免责声明的用户可以使用mailto:方法发送电子邮件,拒绝的用户不会收到弹出窗口。

  • 我在单个页面上有几十个电子邮件地址,所以我需要将地址传递给脚本
  • 免责声明也用于其他页面,所以我也想包括 html 副本,它大约有 4 段。

这就是我到目前为止所拥有的,除了确认时没有弹出邮件客户端外,它几乎可以正常工作:

<a href="mailto:user@domain.com" class="confirm">user@domain.com</a>
<div id='confirm'>
    <div class='header'><span>Confirm</span></div>
    <div class='message'></div>
    <div class='buttons'>
        <div class='no simplemodal-close'>Cancel</div>
        <div class='yes'>Confirm</div>
    </div>
</div>

和JavaScript:

jQuery(function ($) {
    $('a.confirm').click(function (e) {
        e.preventDefault();
        msg = 'this is the copy of the confirmation dialog I want to pop up, it goes on and on and on';
        // example of calling the confirm function
        // you must use a callback function to perform the "yes" action
        confirm(msg, function () {
            window.location.href = hrefval;
        });
    });
});
function confirm(message, callback) {
    $('#confirm').modal({
        closeHTML: "<a href='#' title='Close' class='modal-close'>x</a>",
        position: ["20%",],
        minWidth: '660px',
        minHeight: '400px',
        overlayId: 'confirm-overlay',
        containerId: 'confirm-container', 
        onShow: function (dialog) {
            var modal = this;
            $('.message', dialog.data[0]).append(message);
            // if the user clicks "yes"
            $('.yes', dialog.data[0]).click(function () {
                // call the callback
                if ($.isFunction(callback)) {
                    callback.apply();
                }
                // close the dialog
                modal.close(); // or $.modal.close();
            });
        }
    });
}

想通了,我只需要明确地获取 href 值。

jQuery(function ($) {
    $('a.confirm').click(function (e) {
        e.preventDefault();
        href = $(this).attr('href');
        msg = 'this is the copy of the confirmation dialog I want to pop up, it goes on and on and on';
        // example of calling the confirm function
        // you must use a callback function to perform the "yes" action
        confirm(msg, function () {
            window.location.href = href;
        });
    });
});

最新更新