This article mainly introduces the existence of functions and parameter problems in the JavaScript jQuery library, including passing function parameters and checking whether a jQuery method exists. For more information, see
JQuery function parameter transfer
External variables are used in jQuery's function:
// How to obtain the I variable for (I = 0; I <3; I ++) {$. get ("/test.html", function (data) {alert (I)}) ;}// use closure: for (I = 0; I <3; I ++) {(function (index) {$. get ("/test.html", function (data) {alert (index)}) ;}) (I )}
JavaScript and jQuery check whether a function exists
The method for detecting whether a function exists in JavaScript is:
If (typeof $ form. validate = 'function') {console. log ('This function exists ');} else {console. log ('This function does not exist ');}
For example, you need to check whether an MD5 method exists:
If (typeof window. md5 = 'function') {// md5 (286) is called only when the method is pure );}
To check whether a jQuery method exists, use the following method:
If (jQuery. isFunction (jQuery. fn. rtFunction) {// if this method exists, call jQuery (document). rtFunction ();}