js判断js文件有没有引入,一般引入的js文件里面都会有函数和对象是否存在
可以通过js的typeof判断
1.判断对象

if(typeof jQuery.colorbox == 'undefined') 
{ 
    document.write("<script src=\"jquery.colorbox-min.js\" type=\"text/javascript\"><\/script>"); 
} 

2.判断函数

if(typeof("function_name")=="function") 
{ 
    alert("Function exists!"); 
}

发表评论