Home > Web Front-end > JS Tutorial > How to determine whether a function exists in jquery

How to determine whether a function exists in jquery

藏色散人
Release: 2022-12-30 11:11:32
Original
3109 people have browsed it

Jquery method to determine whether a function exists: first create a code sample file; then pass "if($.isFunction(fun)){eval("testFun('txt')");}}catch( e){$.alert...}" statement can be used to determine whether the function exists.

How to determine whether a function exists in jquery

The operating environment of this tutorial: windows7 system, jquery1.10.0 version, Dell G3 computer.

Recommended: jQuery video tutorial

jquery determines whether the function exists?

You can use the $.isFunction() function in jquery to determine whether the function exists. The $.isFunction() function is used to determine whether the specified parameter is a function.

Example:

var fun = "testFun";  // 函数的名称
try{
 if($.isFunction(fun)){
     eval("testFun('txt')");   // "txt"是函数参数
 } 
}catch(e){ 
  $.alert(fun +'不是函数!'); 
}
Copy after login

Note the use of "eval()"!!!

The above is the detailed content of How to determine whether a function exists in jquery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template