Home > Web Front-end > JS Tutorial > The existence of functions and parameter issues in JavaScript's jQuery library_jquery

The existence of functions and parameter issues in JavaScript's jQuery library_jquery

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 15:45:20
Original
1068 people have browsed it

jQuery function parameter passing

Using external variables in jQuery’s function:

//如何取得i的变量
for(i=0;i<3;i++) {
 $.get("/test.html", function(data){ 
  alert(i)
 });
}


//使用闭包:
for(i=0;i<3;i++) {
 (function(index){
  $.get("/test.html", function(data){ 
  alert(index)
  });
 })(i)
}

Copy after login


JavaScript and jQuery detect whether a function exists

The method to detect whether a function exists in JavaScript is:

if(typeof $form.validate == 'function') {
 console.log('该 function 存在');
} else {
 console.log('该 function 不存在');
}

Copy after login

For example: Need to detect whether an MD5 method exists:

if(typeof window.md5 == 'function') {
 // 如果纯在该方法,才去调用
 md5(286);
}

Copy after login

To detect whether a jQuery method exists, you can use the following method:

if( jQuery.isFunction(jQuery.fn.rtFunction) ) {
 // 如果该方法存在,才去调用
 jQuery(document).rtFunction();
}

Copy after login

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
What are JavaScript hook functions?
From 1970-01-01 08:00:00
0
0
0
What is JavaScript garbage collection?
From 1970-01-01 08:00:00
0
0
0
c++ calls javascript
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template