我有一個JavaScript文件,它也使用jQuery。加載它,我寫了這個代碼:在另一個js文件中加載jQuery
function include(filename)
{
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.src = filename;
script.type = 'text/javascript';
head.appendChild(script)
}
include('http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js');
alert("1");
$(document).read(function(){});
alert("2");
這將激活alert("1")
,但第二alert
不起作用。當我檢查元素時,我看到一個錯誤,表示$
未定義。
我應該如何解決這個問題?
+1不需立即訴諸腳本加載器即可得到詳細的答案(這可能是我會做的:) –