由於我無法控制的原因,我必須通過動態附加的<script>
標籤加載jQuery,並且僅在某些任意事件時執行此操作,而不是在做任何事件時執行此操作,在頁面加載時爲。
我的問題是在檢測的時刻jQuery是準備好了,下面的代碼無法正常工作:
(function(){
var s=document.createElement('script');
s.setAttribute('type','text/javascript');
s.setAttribute('src','http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js');
document.getElementsByTagName('head')[0].appendChild(s);
})()
$(document).ready(function() {
// something that uses jquery and currently doesn't work
});
如何檢測的時刻jQuery是準備在這個特定的配置中使用?
在此先感謝
是JS的FILA總是動態加載? – 2011-01-24 14:21:07
動態加載的javascript文件是如何做的? – 2011-01-24 14:23:21
可能重複。去檢查這些問題: - http://stackoverflow.com/questions/3032721/async-load-javascript-files-with-callback - http://stackoverflow.com/questions/4249030/load-javascript-async-then- check-dom-loaded-before-execution-callback – 2011-01-24 14:23:06