簡體   English   中英

書簽時出現Javascript意外標識符

[英]Javascript unexpected identifier while bookmarkleting

我有這段代碼可以正常工作:

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();
}

但是,當我嘗試通過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();}})();

建議?

謝謝

不知道這是否是bookmarkleter中的錯誤,但是在document.getElementsByTagName("head")[0].appendChild(script_tag);之前需要使用分號document.getElementsByTagName("head")[0].appendChild(script_tag); 如果將所有內容壓縮成這樣的一行。

完成此操作后,意外的標識符錯誤就會消失。 除非您實際上已經預先定義了main否則您將得到一個新的錯誤“ main not defined”。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM