仅在满足javascript条件的情况下加载整个jquery内容 [英] only load the whole jquery stuff if a javascript condition is fulfilled
本文介绍了仅在满足javascript条件的情况下加载整个jquery内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检查一下,在我的php生成的论坛页面上是否有大图像,并且只有在这样的情况下,我才想加载jquery并执行一些jquerystuff .
I would like to check, if there are more than tho large images on my php-generated forum-page, and only if so, then I would like to load jquery and do some jquerystuff.
仅在条件成功的情况下,如何才能动态加载库?
How can I dynamically load the library only if the condition succeeds?
推荐答案
(function() {
if (something) {
var s = document.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.src = '//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js';
(document.getElementsByTagName('head')[0] ||
document.getElementsByTagName('body')[0]).appendChild(s);
}
}());
这篇关于仅在满足javascript条件的情况下加载整个jquery内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文