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.
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 +'不是函数!'); }
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!