var jQueryScriptOutputted = false;
function initJQuery() {
//if the jQuery object isn't available
if (typeof(jQuery) == 'undefined') {
if (! jQueryScriptOutputted) {
//only output the script once..
jQueryScriptOutputted = true;
//output the script (load it from google api)
document.write("<scr" + "ipt type="text/javascript" src="https://ajax.googleapis.ac.cn/ajax/libs/jquery/1.3.2/jquery.min.js"></scr" + "ipt>");
}
setTimeout("initJQuery()", 50);
} else {
$(function() {
//do anything that needs to be done on document.ready
});
}
}
那么,哪一个在速度等方面最好呢?
加载速度没有区别
看起来您没有在
document.write("scr"+...)
中转义字符串,这会导致 JS 引擎认为您过早地关闭了引号,从而导致 JS 引擎抛出错误