站长资源网络编程
Javascript 判断是否存在函数的方法
简介复制代码 代码如下: window.onload=function(){ try{ if(test&&typeof(test)=="function"){ test(); }else{ alert("不存在的函数"); } }catch(e){ } } function test(){ alert(
复制代码 代码如下:
window.onload=function(){
try{
if(test&&typeof(test)=="function"){
test();
}else{
alert("不存在的函数");
}
}catch(e){
}
}
function test(){
alert("函数执行……");
}
如果不存在,会抛出异常,所以要加try……catch。
window.onload=function(){
try{
if(test&&typeof(test)=="function"){
test();
}else{
alert("不存在的函数");
}
}catch(e){
}
}
function test(){
alert("函数执行……");
}
如果不存在,会抛出异常,所以要加try……catch。