Jquery 从插件外部更改默认值
我的插件是:Jquery 从插件外部更改默认值,jquery,plugins,Jquery,Plugins,我的插件是: $.fn.iPopup = function() { var opts = new function() { this.width = 957; this.height = 590; this.left = ($(document).width() / 2) - (this.width/2) - (17/2); this.top = 160; } alert (opts.width); }
$.fn.iPopup = function() {
var opts = new function() {
this.width = 957;
this.height = 590;
this.left = ($(document).width() / 2) - (this.width/2) - (17/2);
this.top = 160;
}
alert (opts.width);
}
我想在调用插件时更改宽度或高度,如:
$('div#tP').iPopup({width:280});
我应该在插件中做什么
$.fn.iPopup = function(options) {
var defaults = {
'width' : 957,
'height' : 590,
'left' : ($(document).width() / 2) - (this.width()/2) - (17/2),
'top' : 160
},
opts=$.extend({}, defaults, options);
}
叫它
$('div#tP').iPopup({width:280});
叫它
$('div#tP').iPopup({width:280});