js、jquery扩展

来源:互联网 发布:淘宝介入怎么操作 编辑:程序博客网 时间:2024/09/21 06:32

js扩展:

1.string扩展:

String.portotype.ResetBlank =functions(){}

str.ResetBlank ();

 

2.数字扩展:

Number.portotype.LenWithZero=function(){}

 

3.数字扩展:

Array.portotype.Min2Max=function(){}

 

总结:

 

类型.prototype.扩展方法名

 

 

 

 

 

 

 

 

 

jquery扩展:

 

1.类级别扩展:

a.定义全局函数:

jQuery.foo=function(){}         使用:$.foo();

b.使用extend定义:

jquery.extend({foo1:function(){}})    使用:$.foo1();

c.使用命名空间定义:

jquery.plugin={foo2:function{}}       使用:$.plugin.foo2();

 

 

2.对象级别扩展:

(function($){
$.fn.foo4 = function() {
alert('对象级别插件fn方式');
}
})(jQuery);

 

 

使用:$('#test').foo4();

 

 

 

 

 

 

 

 

 

 

 

 

 

 

0 0