js 判断js函数、变量是否存在的简单示例代码
(编辑:jimmy 日期: 2025/12/27 浏览:3 次 )
核心代码
//是否存在指定函数
function isExitsFunction(funcName) {
try {
if (typeof(eval(funcName)) == "function") {
return true;
}
} catch(e) {}
return false;
}
//是否存在指定变量
function isExitsVariable(variableName) {
try {
if (typeof(variableName) == "undefined") {
//alert("value is undefined");
return false;
} else {
//alert("value is true");
return true;
}
} catch(e) {}
return false;
}
更多的判断可以参考这篇文章:https://www.jb51.net/article/67551.htm
下一篇:js 事件截取enter按键页面提交事件示例代码