当前位置: 代码迷 >> JavaScript >> js判断步骤是否存在
  详细解决方案

js判断步骤是否存在

热度:66   发布时间:2012-08-29 08:40:14.0
js判断方法是否存在
有个方法:
function test(){
}


如果当前页面有test这个方法,则调用;没有,则不处理。

首先要要判断test是否为空:
typeof test!='undefined'

如果为空,则不需进行处理;不为空,继续判断是不是方法:
testinstanceof Function)


最后代码如下:
if(typeof test!='undefined'&test instanceof Function)      	
    test ();
}
  相关解决方案