jQuery.fn.extend()方法
實例
添加兩個方法到jQuery原型($.fn)
< label > < input type = " checkbox " name = " foo " > Foo </ label >
< label > < input type = " checkbox " name = " bar " > Bar </ label >
< script > $ ( function ( ) { $. fn . extend ( {
check : function ( ) {
return this . each ( function ( ) {
this . checked = true ; } ) ; } , uncheck : function ( ) {
return this . each ( function ( ) {
this . checked = false ; } ) ; }
} ) ; // 使用新創建的.check()方法 $ ( " input[type='checkbox'] " ) . check ( ) ; } ) </ script >
嘗試一下»
定義和用法
$.fn.extend() 函數為jQuery擴展一個或多個實例屬性和方法(主要用於擴展方法)。
提示: jQuery.fn是jQuery的原型對象,其extend()方法用於為jQuery的原型添加新的屬性和方法。 這些方法可以在jQuery實例對像上調用。
語法
$.fn.extend( object )
参数 | 描述 |
---|---|
object | Object类型 指定的对象,用来合并到jQuery的原型对象上。 |