![](/img/trans.png)
[英]How to prevent jQuery function from being initialized more than once (Drupal behaviours involved)?
[英]Prevent jquery from being referenced more than once?
我可以在jquery包含文件的正文中包裹一些內容,以防止它被兩次包含嗎? 我的問題是我的應用程序具有多個包含,並且我想防止jquery在多個包含中被引用而中斷。
我的想法是打開我的jquery文件(jquery-1.4.2.js),並對整個jquery庫代碼塊添加某種邏輯。
就像是:
if(jQueryIsAlreadyIncluded()){// jquery庫代碼{(function(A,w){function ma(){if(!c .......
}
嘗試這個
if(typeof jQuery == 'undefined'){
//jquery library code {(function(A,w){function ma(){if(!c.......
}
Hmmmmm Boilerplate在使用googleapi jQuery時會執行此操作,因此您也可以將其用於本地文件
<script>window.jQuery || document.write('<script src="yourpathtojquery"><\/script>')</script>
但是,這僅適用於jquery本身,否則,您可以設置一些變量,然后在每個庫中檢查是否設置了變量,如果沒有設置,則排除.....
if(!($Mylib))
{
//Your javascript here....
Mylib = true;
}
也許
if (typeof jQuery === undefined) {
// jQuery code
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.