2016-09-22 24 views
0

https://mreidsma.github.io/bookmarklets/jquerify.html在哪裏添加jQuery書籤的addtional邏輯?

道歉事先爲這個新手的javascript問題...上面的鏈接很好地加載jQuery。不過,我想添加額外的jQuery選擇器語句,如下所示:

$('#mruSelect')。hide();

然而,這看起來是一個時間的問題,我不知道在哪裏下面的代碼,我可以jQuery的加載後安全地添加這個...

javascript:(function(){var el=document.createElement("div"),b=document.getElementsByTagName("body")[0],otherlib=!1,msg="";el.style.position="fixed",el.style.height="32px",el.style.width="220px",el.style.marginLeft="-110px",el.style.top="0",el.style.left="50%25",el.style.padding="5px 10px",el.style.zIndex=1001,el.style.fontSize="12px",el.style.color="#222%22,el.style.backgroundColor=%22#f99%22;function%20showMsg(){var%20txt=document.createTextNode(msg);el.appendChild(txt),b.appendChild(el),window.setTimeout(function(){txt=null,typeof%20jQuery==%22undefined%22?b.removeChild(el):(jQuery(el).fadeOut(%22slow%22,function(){jQuery(this).remove()}),otherlib&&(window.$jq=jQuery.noConflict()))},2500)}if(typeof%20jQuery!=%22undefined%22)return%20msg=%22This%20page%20already%20using%20jQuery%20v%22+jQuery.fn.jquery,showMsg();alert('test');typeof%20$==%22function%22&&(otherlib=!0);function%20getScript(url,success){var%20script=document.createElement(%22script%22);script.src=url;var%20head=document.getElementsByTagName(%22head%22)[0],done=!1;script.onload=script.onreadystatechange=function(){!done&&(!this.readyState||this.readyState==%22loaded%22||this.readyState==%22complete%22)&&(done=!0,success(),script.onload=script.onreadystatechange=null,head.removeChild(script))},head.appendChild(script)}getScript(%22//code.jquery.com/jquery.min.js%22,function(){return%20typeof%20jQuery==%22undefined%22?msg=%22Sorry,%20but%20jQuery%20was%20not%20able%20to%20load%22:(msg=%22The%20Recent%20Items%20is%20now%20hidden%22,otherlib&&(msg+=%22%20and%20noConflict().%20Use%20$jq;,%20not%20$().%22)),showMsg()})})(); 

有埋在那裏的警報語句我補充說,它的工作原理,但添加jQuery不會工作,因爲它還沒有。

+0

您是否嘗試過以下鏈接。我發現它非常適用於爲純JS或JQuery格式化書籤。http://mrcoles.com/bookmarklet/ –

回答

0

我確定你不能保證jQuery是否被加載。所以我決定在showMsg()之後添加以下內容:函數調用。

document.getElementById('mruSelect').style.display = 'none';