0
点赞
收藏
分享

微信扫一扫

jquery 插件的api变动

一、jquery 插件中的方法 暴露方式:


1、以前常常使用 "对象.公用方法();"的方式调用;

(function($) {

$.fn.wBox = function(options) {

var defaults = {

wBoxURL : basePath + "css/wbox/",

opacity : 0.6,

callBack : null,

noTitle : false,

show : false,

timeout : 0,

target : null,

requestType : null,

title : "wBox Title",

drag : true,

closeCallBack : null

}, _this = $(this);

var setting =  $.extend(defaults,options);  



//公用的方法

this.funA(_a,_b) {};

this.funB() {};



return this;

}

})(jQuery);

var a = $('#a').wBox({...});

a.funA('1','2');//方法的调用



2、最近的jquery插件在api上发生了很大变化,尤其是方法调用上多数使用如下方式: $("#...").uploadify('方法名',参数...);

(function($) {

var methods = {

init:function (options) {

var $this = $(this);

var settings = $.extend({

id:'',

name:'',

...

},options);


},

funA:function (_a,_b) {

。。。

},

funB:function() {

。。。

}

}



$.fn.uploadify = function(method) {

if (methods[method]) {

return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));

} else if (typeof method === 'object' || !method) {

return methods.init.apply(this, arguments);

} else {

$.error('The method ' + method + ' does not exist in $.uploadify');

}

}

})(jQuery);



$('#a').uploadify({...});

$('#a').uploadify('funA','1','2');//调用方法



举报

相关推荐

0 条评论