开发者

jquery simplemodal unable to call another function

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(fu开发者_Go百科nction() {
    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();
            }
        }
    });
}


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

});

});


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

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜