jQuery API 返回首页目录 | jQuery API 中英文对照版
$.extend(prop)
$.extend(prop)

扩展jQuery对象。可以用于把函数添加到jQuery名称空间中,以及添加插件方法(插件)。

返回值:Object

参数:

  • prop (Object): 要合并到jQuery对象中的对象
 
示例:

添加两个插件方法。

jQuery 代码:

jQuery.fn.extend({
  check: function() {
    return   this.each(function() { this.checked = true; });
  }, 
  uncheck: function() {
    return   this.each(function() { this.checked = false; });
  }
});
$("input[@type=checkbox]").check(); 
$("input[@type=radio]").uncheck(); 
示例:

向jQuery名称空间中添加两个函数。

jQuery 代码:

 jQuery.extend({
     min: function(a, b) { return a < b?? a?: b; },
     max: function(a, b) { return a > b?? a?: b; } 
  });  
 
$.fn.extend( prop )

Extends the jQuery object itself. Can be used to add functions into the jQuery namespace and to add plugin methods (plugins).

Return value: Object
Parameters:

  • prop (Object): The object that will be merged into the jQuery object
 

Example:

Adds two plugin methods.

 jQuery.fn.extend({  
   check: function() { 
      return this.each(function() { this.checked = true; });
     }, 
    uncheck: function() { 
      return this.each(function() { this.checked = false; });
     }
   });
   $("input[@type=checkbox]").check();
   $("input[@type=radio]").uncheck();  
 

Example:

Adds two functions into the jQuery namespace

 jQuery.extend({
     min: function(a, b) { return a < b?? a?: b; },
     max: function(a, b) { return a > b?? a?: b; } 
  });  

 

相关链接
asp之家 | jQuery官方网站 | jQuery中文网 | 电子书作者网站 | 电子书作者blog