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:2:3:4:Custom Method!5:
6: <script type = "text/javascript" src = "js/jquery-2.1.1.js"> </script> 7: <script type = "text/javascript"> 8: jQuery (function () 9: {10: $ ("form input "). disable (); 11 :}); 12: </script> 13:14:15:Test the custom method to disable the form element.
16: 20:21:
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