我想知道当我在页面中添加jquery时,我想在添加之前检查是否已经添加了jquery,如果没有添加,那么只添加其他不添加。
例如,我添加了jquery jquery-1.4.1.min
<script type="text/javascript" src="<?php echo SITE_JS;?>jquery-1.4.1.min"></script>在此之后,当我尝试添加jquery jquery-1.7.1.min时
in case i didnt know that i have already added or not,所以我尝试添加它,但在此之前,我想检查版本,如果jquery与旧版本或相同,那么我不希望它添加,否则添加新的jquery并禁用旧的。
<script type="text/javascript" src="<?php echo SITE_JS;?>jquery-1.7.1.min"></script>在添加这个之前,我想检查一下jquery是否已经存在更高版本。这怎么可能呢?
发布于 2013-05-30 19:10:10
像这样试一下,
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
window.jQuery || document.write('<script src="<?php echo SITE_JS;?>/jquery-1.9.1.min.js"><\/script>');
// you should have jquery-1.9.1.min.js on the site url
</script>发布于 2013-05-30 19:12:04
尝试此方法以检查是否加载了jquery或not...if加载了打印版本...
if (typeof jQuery != 'undefined') {
// jQuery is loaded => print the version
alert(jQuery.fn.jquery);}根据版本编写一个逻辑来加载您的jquery版本...
发布于 2013-05-30 19:12:52
使用"window.load“事件
(function() {
if (window.addEventListener) {
// Standard
window.addEventListener('load', jQueryCheck, false);
}
else if (window.attachEvent) {
// Microsoft
window.attachEvent('onload', jQueryCheck);
}
function jQueryCheck() {
if (typeof jQuery === "undefined") {
// No one's loaded it; either load it or do without
}
}
})();https://stackoverflow.com/questions/16834510
复制相似问题