判断Javascript 是否存在函数
2013-01-02 19:36:21 来源:WEB开发网核心提示: 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。