龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > Javascript编程 >

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

时间:2014-08-19 12:43来源:网络整理 作者:网络 点击:
分享到:
这篇文章主要介绍了使用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>
精彩图集

赞助商链接