JQuery未捕获类型错误:modal.open不是函数

JQuery未捕获类型错误:modal.open不是函数,jquery,Jquery,我试图通过点击一个链接来显示一个模式窗口。但是,控制台返回一个未捕获类型错误:modal.open不是一个函数。我检查了一下,确保我在需要的地方都放了分号。任何有新眼光的人都知道我错过了什么吗 HTML JQUERY var modal=(函数(){ 变量 方法={}, $overlay, $modal, $content; //附加HTML $overlay=$(''); $modal=$(''); $content=$(''); $modal.hide(); $overlay.hide

我试图通过点击一个链接来显示一个模式窗口。但是,控制台返回一个
未捕获类型错误:modal.open不是一个函数
。我检查了一下,确保我在需要的地方都放了分号。任何有新眼光的人都知道我错过了什么吗

HTML

JQUERY
var modal=(函数(){
变量
方法={},
$overlay,
$modal,
$content;
//附加HTML
$overlay=$('');
$modal=$('');
$content=$('');
$modal.hide();
$overlay.hide();
$modal.append($content);
$(文档).ready(函数(){
$('body')。追加($overlay,$modal);
});
$(“#覆盖”)。单击(函数(e){
e、 预防默认值();
方法close();
});
//在视口中使模态居中
method.center=函数(){
左上角;
top=Math.max($(窗口).height()-$modal.outerHeight(),0)/2;
左=数学.max($(窗口).width()-$modal.outerWidth(),0)/2;
$modal.css({
top:top+$(窗口).scrollTop(),
左:左+$(窗口)。滚动左()
});
};
//打开模型
method.open=函数(设置){
$content.empty().append(settings.content);
$modal.css({
宽度:settings.width | |“自动”,
高度:设置。高度| |“自动”
});
方法。中心();
$(window.bind('resize.model',method.center));
$modal.show();
$overlay.show();
};
//关闭模式
method.close=函数(){
$modal.hide();
$overlay.hide();
$content.empty();
$(window.unbind('resize.modal');
};
返回法;
});
$(文档).ready(函数(){
$(“#导航下载”)。单击(功能(e){
e、 预防默认值();
打开({content:“获取一个链接,将我们的免费移动应用下载到您的智能手机上!

”}); }); });

modal
是一个函数。它没有
open
属性

我想你是想运行这个函数。尝试:

var modal = (function(){
    // ...
}());
// ^ Notice the `()` here

modal
是一个函数,而不是一个对象。您需要执行以下操作:

var m = modal();
m.open(...);
或者在分配
模式时,使用iLife立即调用函数,如火箭危险品的回答中所示

var modal = (function(){
    // ...
});
var modal = (function(){
    // ...
}());
// ^ Notice the `()` here
var m = modal();
m.open(...);