2013-12-11 45 views
1

我寫了一個使用jQuery的腳本(http://jsfiddle.net/vishnukanwar/yqH5B/),它在頁面加載時顯示一個social-like_button div。雖然此div顯示其他所有內容都模糊不清。如何在Google Blogger中添加jQuery而無需修改模板?

我的麻煩是,這個jQuery腳本在我的桌面(本地和jsfiddle)上工作正常,但是一旦我發佈到Blogger,它不起作用。

我覺得Blogger不會同步加載jQuery(即使它被要求),這就是爲什麼它顯示'jQuery是未定義'的錯誤。

var jq = document.createElement('script'); 
    //jq.src = "//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"; 
    jq.src = "https://code.jquery.com/jquery-1.10.1.min.js"; 
    jq.onload = jq.onreadystatechange = loadPopupBox; // for function def check [link][2] 
    document.getElementsByTagName('head')[0].appendChild(jq); 

誰能告訴我如何在Google Blogger中動態和同步添加jQuery而無需修改我的Blog模板?

+0

我得到了解決方案:) –

回答

0

...這裏是Blogger.com絕對正常的代碼。我加在www.tcft.in

<script> 
    function MyScript() 
    { 
     if (typeof jQuery === "undefined") { 
      alert ("jQuery is undefined"); 
     } else { 
      alert ($("head").text()); 
     } 
    } 

    function LoadJQuery (onload) 
    { 
     if (typeof jQuery !== "undefined") { 
      if (typeof onload !== "undefined") script.onload = onload; 
     } else { 
      var script = document.createElement('script'); 
      if (typeof onload !== "undefined") script.onload = onload; 
      script.src = "//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"; 
      script.async = false; 
      document.head.appendChild(script); 
     } 
    } 

    LoadJQuery(function() { MyScript() }); 

</script> 
相關問題