1、jQuery.fn.extend(object)
扩展 jQuery 元素集来提供新的方法(通常用来制作插件)。相当于成员方法。
举例:使指定元素下面的input元素可用和不可用。
$.fn.extend({ disable:function(){ return $(this).each(function(){$(this).find("input").attr("disabled","disabled");}); }, enable:function(){ return $(this).each(function(){$(this).find("input").attr("disabled","");}); } });
html代码
<div id='test'>
<INPUT TYPE="text" >
<INPUT TYPE="checkbox" >
</div>
调用
$("#test").disabled(); $("#test").enabled();
2、jQuery.extend(object)
在jQuery命名空间上增加两个函数。相当于静态方法。
jQuery.extend({ min: function(a, b) { return a < b ? a : b; }, max: function(a, b) { return a > b ? a : b; } });
调用
alert($.max(2,3)); alert($.min(2,3));