我想在myjs.js文件中包含jquery.js。我爲此寫了下面的代碼。如何將jquery.js包含在另一個js文件中?
var theNewScript=document.createElement("script");
theNewScript.type="text/javascript";
theNewScript.src="http://example.com/jquery.js";
document.getElementsByTagName("head")[0].appendChild(theNewScript);
$.get(myfile.php);
第5行顯示錯誤'$ not defined'。我想包含jquery.js,然後在myjs.js文件中調用$ .get()函數。我怎樣才能做到這一點? 請幫我
爲什麼你想要在頁面之外使用$ .get()? – Calum 2011-04-07 08:05:50
我假設你打算說'$ .get(「myfile.php」);'而不是'$ .get(myfile.php);'。 – 2011-04-07 08:22:43
[檢查jquery是否已被加載,然後加載它如果爲false]可能的重複(http://stackoverflow.com/questions/1828237/check-if-jquery-has-been-loaded-then-load-it-if - 假) – 2014-06-01 08:25:33