1

在我的模态窗口中,我有一个“继续”按钮。虽然我可以通过使用 simplemodal-close 类分配按钮来关闭模式,但我无法让它调用我的函数。我从网站上的简单演示中整理了这段代码。

按钮:

<a href="#" class="simplemodal-close" onClick="closePopup()"><img src="bell/images/button_understand.gif" width="116" height="49"></a>

的JavaScript:

$(document).ready(function() {
    function showPopups(){
        var e = document.getElementById('hirpopup');
        $('#hirpopup').modal({
        opacity:80,
        overlayCss: {backgroundColor:"#fff"}
        });
    e.style.display = 'block';
    return false;
    }

    function closePopup(){
        var e = document.getElementById('hirpopup');
        e.style.display = 'none';

        confirm(function () {
        sameWindow(this.form);
        });
    }

    function confirm(callback) {
        $('#hirpopup').modal({
            onShow: function () {
                var modal = this;
                // call the callback
                if ($.isFunction(callback)) {
                    callback.apply();
                }
            }
        });
    }
});

任何想法,因为我对 jQuery 很陌生,对 simplemodal 完全陌生。

编辑:我已经按如下方式更新了我的 javascript,但是它仍然没有执行我的功能。我收到了 1 的警报,以及其中包含该功能的警报,但没有别的。

$(document).ready(function(){
    $("#close").css("cursor", "pointer"); 

    $('#next').click(function(){
        var e = document.getElementById('hirpopup');
        $('#hirpopup').modal({
            opacity:80,
            overlayCss: {backgroundColor:"#fff"}
        });
        e.style.display = 'block';
        return false;
    });

    $('#close').click(function(){
        var e = document.getElementById('hirpopup');
        e.style.display = 'none';

        confirm(function () {
            sameWindow(this.form);
        });
    });
});


function confirm(callback) {
alert("1");
alert(callback);
    $('#hirpopup').modal({
        onShow: function () {
            alert("2");
            var modal = this;
            // call the callback
            if ($.isFunction(callback)) {
                alert("3");
                callback.apply();
            }
        }
    });
}
4

2 回答 2

1

编辑:您可以尝试将确认方法放入 document.ready 中。这可能是一个问题

您不能在自己的函数中包含 $(document).ready,但它应该是根方法。也使用 jQuery 事件绑定

    $(document).ready(function() {

$('.simplemodal-close').click({

        var e = document.getElementById('hirpopup');
        e.style.display = 'none';

        confirm(function () {
            sameWindow(this.form);
        });

});

});

于 2010-11-16T12:36:55.007 回答
0

你不能 $(document).ready(function(){})在你的函数里面。它仅在您的页面加载时自动执行一次。

而是写

function closePopup(){

        var e = document.getElementById('hirpopup');
        e.style.display = 'none';

        confirm(function () {
            sameWindow(this.form);
        });

}
于 2010-11-16T12:27:07.903 回答