;(function($,window,document,undefined) {
// 定义 ConstructionObj 的构造函数
function ConstructionObj (ele,opt) {
var _ = this;
_.$element = ele, // ele接收参数中的this实参,为jQuery选中的元素
_.defaults = { // 默认参数
type: '',
uid : '',
}
_.options = $.extend({},_.defaults,opt); // 合并参数
_.getAjax = function(type, url, params , asynctype , callback) {
var html = $.ajax({
type: type,
url: url,
dataType: 'jsonp',
data: params,
async: asynctype,
jsonp: "callback", //服务端用于接收callback调用的function名的参数
success: res => callback(res),
error: err => callback(error),
})
};
}
//定义ConstructionObj的原型方法
ConstructionObj.prototype = {
// 初始函数
init: function() {
var _ = this;
_.getAjax();
}
}
$.fn.constructionObj = function(options) {
window.constructionObj = new ConstructionObj(this,options);
return constructionObj.init();
}
})(jQuery,window,document);
// 初始调用
$(function() {
$("#container").constructionObj({
'type': 'PC',
'uid' : '420984',
'gid' : '666'
});
});
构造对象 - 并绑定至jQuery原型上
最新推荐文章于 2023-04-25 13:28:23 发布