87,992
社区成员
发帖
与我相关
我的任务
分享
$.fn.wrapChildren = function(options) {
var options = $.extend({
childElem : undefined,
sets : 1,
wrapper : 'div',
classet:''
}, options || {});
if (options.childElem === undefined) return this;
return this.each(function() {
var elems = $(this).children(options.childElem);
var arr = [];
elems.each(function(i,value) {
arr.push(value);
if (((i + 1) % options.sets === 0) || (i === elems.length -1)){
var set = $(arr);
arr = [];
set.wrapAll($("<" + options.wrapper + ">").addClass(options.classet));
}
});
});
};
function overridefn(){
switch(arguments.length){
case 1:
(function(a){
alert('只有一个参数:' + a);
}).apply(this,arguments);
break;
case 2:
(function(a,b){
alert('两个参数:' + a + ' , ' + b);
}).apply(this,arguments);
break;
default:
(function(){
alert('没有参数');
}).apply(this);
break;
}
}
overridefn();
overridefn(1);
overridefn(1,2);
虽然没有重载,但是我们可以模拟