jQuery API | 返回首页目录 | jQuery API 中英文对照版 |
$.extend(prop) |
$.extend(prop)
扩展jQuery对象。可以用于把函数添加到jQuery名称空间中,以及添加插件方法(插件)。 返回值:Object 参数:
添加两个插件方法。 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; } }); Extends the jQuery object itself. Can be used to add functions into the jQuery namespace and to add plugin methods (plugins). Return value: 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; } });
|