首页 > 语言 > JavaScript > 正文

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

2024-05-06 16:07:38
字体:
来源:转载
供稿:网友
这篇文章主要介绍了使用typeof判断function是否存在于上下文,在窗口加载时,使用typeof进行判断,需要的朋友可以参考下
 
 

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

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

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选