您现在的位置: 万盛学电脑网 >> 程序编程 >> 脚本专题 >> javascript >> 正文

使用typeof判断function是否存在于上下文

作者:佚名    责任编辑:admin    更新时间:2022-06-22

 在窗口加载时,使用typeof判断function是否存在于上下文

01 <script type="text/javascript">  02 window.onload = function(){  03 try{  04 if(test && typeof(test) == "function"){  05 test();  06 }  07 }catch(e){  08 alert("方法不存在");  09 }  10 }  11 function test(){  12 alert("我是test()方法");  13 }  14 </script>