【问题标题】:jQuery simplemodal plugin: the method close() is causing errorjQuery simplemodal 插件:方法 close() 导致错误
【发布时间】:2011-02-25 14:47:19
【问题描述】:

当试图关闭 simplemodal 对话框时,正如我在插件的网站示例中看到的那样,它是通过调用来完成的

$.modal.close() or modal.close()

但没有一个对我有用。

在 Chrome 控制台上我得到这个:

Uncaught TypeError: Object #<an HTMLDivElement> has no method 'close' $.live.$.load.$.modal.onClose

这是完整的代码。

$('.FinishUploadedFile').live('click',function(){

        $('<div id="modal"></div>').load('page?n=3',function(){

            $(this).modal({
                overlayClose: true,
                position: ['10%'],
                overlayOpacity:0,
                onOpen: function (dialog) {
                    dialog.overlay.fadeIn('normal', function () {
                        dialog.data.hide();
                        dialog.container.fadeIn('fast', function () {
                            dialog.data.slideDown('fast');
                        });
                    });
                },
                onClose: function (dialog) {
                    dialog.data.fadeOut('normal', function () {
                        dialog.container.slideUp('fast', function () {
                            dialog.overlay.fadeOut('fast', function () {
                                //Close the dialog.
                                modal.close();
                            });
                        });
                    });
                }
            });

        });

});

【问题讨论】:

    标签: jquery jquery-plugins simplemodal


    【解决方案1】:

    你还没有在任何地方声明modal。您需要将 modal.close(); 更改为 $.modal.close(); 或将您的 onClose 函数更改为:

    onClose: function (dialog) {
        var modal = this; // <- add this line
        dialog.data.fadeOut('normal', function () {
            dialog.container.slideUp('fast', function () {
                dialog.overlay.fadeOut('fast', function () {
                    //Close the dialog.
                    modal.close();
                });
            });
        });
    }
    

    【讨论】:

    • 嗨,埃里克,谢谢。最终选择了$.modal.close();解决方案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多