jquery simplemodal无法调用另一个函数

发布于 2024-10-02 12:42:56 字数 2159 浏览 1 评论 0原文

在我的模式窗口中,我有一个“继续”按钮。虽然我可以通过为按钮分配 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();
            }
        }
    });
}

In my modal window I have a "continue" button. Whilst I can get the modal to close by assigning the button with the simplemodal-close class, I can't get it to call my function. I've put together this code from the simple demos on the site.

The button:

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

the 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();
                }
            }
        });
    }
});

Any ideas as I'm pretty new to jQuery and completely new to simplemodal.

EDIT: I've updated my javascript as follows, however its still not doing my function. I get the alert of 1, and the alert with the function in it but nothing else.

$(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();
            }
        }
    });
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

歌枕肩 2024-10-09 12:42:56

编辑:您可以尝试将确认方法放入 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);
        });

});

});

EDIT: you may try to put confirm method inside document.ready. This could be one issue

You cannot have $(document).ready inside your own function, but it should be the root method. Use also the jQuery event binding

    $(document).ready(function() {

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

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

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

});

});

ㄖ落Θ余辉 2024-10-09 12:42:56

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

而是写

function closePopup(){

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

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

}

You cannot have $(document).ready(function(){}) inside your function. It executes automatically only once when your page gets loaded.

instead write

function closePopup(){

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

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

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文