Function and parameter problems in the jQuery library of JavaScript _ jquery

Source: Internet
Author: User
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 ();}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.