The jQuery extension interface defines two user-defined functions for the jQuery framework, and then calls these two functions. The jquery extension Interface
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml" xml: lang = "en">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<Title> two custom functions are defined for the jQuery framework using the jQuery extension interface, and then the two functions are called </title>
<Script type = "text/javascript" src = "jquery-1.11.3.min.js"> </script>
<Script>
JQuery. fn. extend ({// call the extension function
Check: function () {// extension of the check function for form elements. Select the single-choice button or check box.
Return this. each (function () {this. checked = true ;});
},
Uncheck: function () {// extension of the check function for form elements. deselect the single-choice button or check box.
Return this. each (function () {this. checked = false ;});
}
});
$ (Function () {// application extension function
$ ("Input [type = checkbox]"). check ();
$ ("Input [type = radio]"). uncheck ();
});
</Script>
</Head>
<Body>
<Input type = "radio"/>
<Input type = "radio" checked = "checked"/>
<Input type = "checkbox"/>
<Input type = "checkbox" checked = "checked"/>
</Body>
</Html>
In the above Code, jQuery. fn. extend is actually jQuery. extend = jQuery. fn. extend = jQuery. prototype. extend. Readers may wonder if jQuery is used. fn. extends are added to extended functions, which should be $ (xxx) during calls ). extend. xxxx (), instead of the $ (xxx) called by the preceding sample code ). xxxx (), of course, must be called after the code is processed.
The Extended Function extend () contains two custom methods in the form of direct object quantity: check () and uncheck (). The check () method defines the selected status for each form element that jQuery matches. The uncheck () method defines the unselected status for each form element that jQuery matches.