Extension of custom methods in jQuery.
The JQuery package provides a large number of methods that can be directly used on the page. However, no
Any library can meet all requirements. Therefore, the JQuery Library provides a wide range of extension functions.
. Take disabling a group of form elements as an example to see how to add custom elements in the JQuery library.
. (JQuery has no way to disable form elements)
Code:
1: <! DOCTYPE> 2:
The text box and button have been disabled:
If you only disable the button, add a css class;
1: jQuery(function() 2: { 3: $("form input.test").disable(); 4: });
Check whether the button is disabled:
Implementation is also very simple, open the jquery-2.1.1.js source code, no compression, relatively easy, I introduced
And then add the following code
1: jQuery.fn.disable=function () { 2: return this.each(function() 3: { 4: if(this.disabled != null) this.disabled=true; 5: }); 6: }
You can use the method described above.
In the book JQuery In Action, I mentioned the extension In the form of $. fn. Method Name (P12 ).
Tested and disabled. The error is still correct.
For more articles, see
Custom JQuery Extension Method
You later wrote the "showLbtDialog" function, so the call method is $ ("# div"). showLbtDialog ();
To call the original extension, the call method is $. lbtDialog. lbtSetDiv.
You see
JQuery. fn. extend ({
ShowLbtDialog: function (p ){
Var lbt = $. extend (true, {}, $. lbtDialog, p );
Return lbt. lbtSetDiv;
}
In this section, the method has already been called.
How does JQUERY call udfs?
Custom ?? It depends on how you define the method. It can be used directly, for example, function aa () {}, which is directly aa (), if it is a custom method extended to the jQuery object, there are two kinds of usage, one is $. extend ({'aa': function () {}}), which is like this $. aa (), another type such as $. fn. extend ({'aa': function () {}}). this is the case for calling $ (this ). aa ()