![](/img/trans.png)
[英]Load javascript script only when condition is fulfilled - not working
[英]only load the whole jquery stuff if a javascript condition is fulfilled
我想檢查一下,在我的php生成的論壇頁面上是否有大圖像,並且只有這樣,我才想加載jquery並執行一些jquerystuff 。
僅當條件成功時,如何才能動態加載庫?
(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);
}
}());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.