这段代码可以在火狐和Chrome上运行,但不能在IE9上运行。它甚至可以在IE9中的同一个域上工作,但在其他域上失败。控制台显示了一个SCRIPT1002 :语法错误。我将此代码放在jsp中,并使用{domain}/path从我的控制器将其加载到脚本标记中。
(
function(){
var v = "1.9.1";
if (window.jQuery === undefined || window.jQuery.fn.jquery < v ) {
var done = false;
var script = document.createElement("script");
script.src = "http://ajax.googleapis.com/ajax/libs/jquery/" + v + "/jquery.min.js";
script.onload = script.onreadystatechange = function(){
if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {
done = true;
initBookmarklet();
}
};
document.getElementsByTagName("head")[0].appendChild(script);
} else {
initBookmarklet();
}
function initBookmarklet(){
//do stuff here
}
}());发布于 2013-08-01 21:08:49
试着这样写吧
var v = "1.9.1";
if (window.jQuery === undefined || window.jQuery.fn.jquery < v) {
var done = false;
var script = document.createElement("script");
script.src = "http://ajax.googleapis.com/ajax/libs/jquery/" + v + "/jquery.min.js";
script.onload = script.onreadystatechange = function () {
if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {
done = true;
initBookmarklet();
}
};
document.getElementsByTagName("head")[0].appendChild(script);
} else {
initBookmarklet();
}
function initBookmarklet() {
//do stuff here
}https://stackoverflow.com/questions/17972510
复制相似问题