如果jquery不加载,我如何设置备份?
我发现并尝试过这个:
if (typeof jQuery == 'undefined') {
alert('jquery didn't load !');
loadScript("/here/jquery.min.js");
.... // this is where i'd want to say load from '/here/jquery.js'
}
但我不知道如何在脚本中调用脚本的src。
发布于 2012-09-22 21:45:33
这是相当普遍的:
<!-- Grab Google CDN's jQuery. fall back to local if necessary -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"></script>
<script>!window.jQuery && document.write(unescape('%3Cscript src="js/libs/jquery-1.4.2.js"%3E%3C/script%3E'))</script>
发布于 2012-09-22 21:46:00
看这里How can I load jQuery if it is not already loaded?或load jQuery from external source if not loaded
if(typeof jQuery=='undefined') {
var headTag = document.getElementsByTagName("head")[0];
var jqTag = document.createElement('script');
jqTag.type = 'text/javascript';
jqTag.src = 'jquery.js';
jqTag.onload = myJQueryCode;
headTag.appendChild(jqTag);
}
发布于 2012-09-22 21:42:59
在常规HTML中添加一个div,说明jquery没有加载,然后用jquery隐藏它
<div class="jqueryError">
<a> jquery did not load </a>
</div>
$(function(){
$('jqueryError').hide();
});
https://stackoverflow.com/questions/12547904
复制相似问题