slw*_*lwr 1 javascript bookmarklet
我有这段代码可以正常工作:
if (typeof jQuery === "undefined" || jQuery.fn.jquery !== '1.4.2') {
var script_tag = document.createElement('script');
script_tag.setAttribute("type","text/javascript");
script_tag.setAttribute("src","http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js");
script_tag.onload = main; // Run main() once jQuery has loaded
script_tag.onreadystatechange = function () { // Same thing but for IE
if (this.readyState == 'complete' || this.readyState == 'loaded') main();
}
document.getElementsByTagName("head")[0].appendChild(script_tag);
} else {
main();
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试通过 bookmarkleter 压缩它时,出现“意外标识符”错误
javascript:(function(){if(typeof%20jQuery===%22undefined%22%20||%20jQuery.fn.jquery%20!=='1.4.2'){var%20script_tag=document.createElement('script');script_tag.setAttribute(%22type%22,%22text/javascript%22);script_tag.setAttribute(%22src%22,%22http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js%22);script_tag.onload=main;script_tag.onreadystatechange=function(){if(this.readyState=='complete'%20||%20this.readyState=='loaded')main();}document.getElementsByTagName(%22head%22)[0].appendChild(script_tag);}else{main();}})();
Run Code Online (Sandbox Code Playgroud)
建议?
谢谢
不确定这是否是书签程序中的一个错误,但是document.getElementsByTagName("head")[0].appendChild(script_tag);如果它要全部被挤进这样的一行,那么您之前需要一个分号。
一旦执行此操作,意外的标识符错误就会消失。除非您之前已经定义过,否则您将收到“main is not Defined”的新错误main。
| 归档时间: |
|
| 查看次数: |
884 次 |
| 最近记录: |