js判断某个方法是否存在

<script type="text/javascript">
 window.onload = function(){
      try{
           if(test && typeof(test) == "function"){
                test();
               }
          }catch(e){
               alert("方法不存在");
          }
}

 function test(){
      alert("我是test()方法");
 }
</script>

猜你喜欢

转载自blog.csdn.net/ibenxiaohai123/article/details/79993861