2015-10-18 163 views
-1

試過解決JQuery之間的JQuery衝突1.8.2 & 1.4.4與各種Stackoverflow線程中描述的所有方法。但在徒然。Jquery庫衝突 - 無法解決

<script src="js/jquery-1.4.4.min.js" type="text/javascript"></script> 
<script src="js/fshare.js" type="text/javascript"></script> 
<script type="text/javascript"> 
    $(document).ready(function() { 
     $('#floating-bar').fshare({ theme: 'compact', upperLimitElementId: 'upper-limit-element', lowerLimitElementId: 'lower-limit-element' }); 
    }); 
</script> 

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> 
<script>window.jQuery || document.write('<script src="./js/jquery-1.8.2.min.js">\x3C/script>')</script> 

鏈接fshare.js:http://egrappler.com/jquery-floating-social-share-plugin-floatshare/

+0

檢查了這一點 - https://api.jquery.com/jquery.noconflict/ –

+0

[可以在同一頁上使用多個版本的jQuery嗎?]可能的重複(http://stackoverflow.com/questions/1566595/can-i-use-multiple-versions-of-jquery-on-the-same-頁) –

回答

0

這裏jQuery的衝突解決方案:

  var jQueryVersion = '1.11.2'; 
      var callback=function(isExists){ 
        if (isExists) { 
         window.myJquery= jQuery.noConflict(true); 

        } else {      
         window.myJquery= $ 
        } 
        console.log('local jQuery is loaded. Version: '.concat(window.myJquery.fn.jquery)); 
} 
      jQueryCheck: function(callback) { 

       var isExists = true; 
       if (!window.jQuery || !$) { 
        isExists = false; 
        console.log('no jQuery on the site. Injecting JQUERY version: ' + jQueryVersion); 
       } 
       if (!isExists || window.jQuery().jquery !== jQueryVersion) { 

        var jQueryInstance = document.createElement('script'); 

        jQueryInstance.type = 'text/javascript'; 
        jQueryInstance.src = url_to_you_jquery_library 
        jQueryInstance.onload = function() { 
         callback(isExists); 
        }; 
        jQueryGuavaInstance.onreadystatechange = function() { 
         if (this.readyState === 'complete') { 
          callback(isExists); 
         } 
        }; 
        document.getElementsByTagName('head')[0].appendChild(jQueryInstance); 
        if (isExists) { 
         concole.log('jQuery exists on the site. Version: '.concat(window.jQuery().jquery)); 
        } 

       } else { 
        console.log('current site version is equals to newest jquery version. Site version: ' + window.jQuery().jquery + ', Latest JQUERY version: ' + jQueryVersion); 
       } 

      },