如何判断一个jquery对象是否存在
如何判断一个jquery对象是否存在
判定方法
jquery是一个操作类,引入失败的话建议手动加载,要不然网站无法正常运行。这种行为主要是引用了CDN
http://apps.bdimg.com/libs/jquery/1.6.4/jquery.js http://apps.bdimg.com/libs/jquery/1.6.4/jquery.min.js http://apps.bdimg.com/libs/jquery/2.1.1/jquery.js http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js
if($&&typeof($)=='object'&&$().length>0){ alert('$ is jqueryBar'); }else{ alert('$ is jqueryBar'); // 如果失败可以根据需要把上面地址中的版本号更换以下就可以引用对用的jquery版本。 js('/public/w/dump.js', true); } //载入js function js(a, j) { var e = document.createElement('script'); e.setAttribute('type', 'text/javascript'); e.setAttribute('src', a); document.body.appendChild(e); }
原文链接:http://www.fastmvc.com/blog/1266.html