2011-01-05 68 views
2

我發現在bookmarklets中鏈接和加載jquery的例子,但無法找到jquery和jquery-ui都加載的情況。如何嵌套cdn加載jquery和jquery-ui在書籤中?

這裏是我的工作要點: link text 更新的以下要點是現在功能。

<a href='javascript:(function(e,a,g,h,f,z,c,b,d){if(!(f=e.jQuery)||g>f.fn.jquery||h(f)){c=a.createElement("script");c.type="text/javascript";c.src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js";c.onload=c.onreadystatechange=function(){z=a.createElement("script");z.type="text/javascript";z.src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/jquery-ui.min.js";z.onload=z.onreadystatechange=function(){if(!b&&(!(d=this.readyState)||d=="loaded"||d=="complete")){h((f=e.jQuery).noConflict(1),b=1);f(c).remove()}};a.documentElement.childNodes[0].appendChild(c)}}})(window,document,"1.4.4",function($,L){/*ENTER JQUERY-UI CODE HERE*/});'>CC</a> 

回答

2

我得到了以下書籤工作:

javascript: 
(function(){ 
    var s1=window.document.createElement('script'); 
    s1.setAttribute('src','http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js'); 
    window.document.body.appendChild(s1); 
    var s2=window.document.createElement('script'); 
    s2.setAttribute('src','http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/jquery-ui.min.js'); 
    window.document.body.appendChild(s2); 
    s1.onload=s1.onreadystatechange=function(){ 
    if(!this.readyState||this.readyState=='loaded'||this.readyState=='complete'){ 
     s2.onload=s2.onreadystatechange=function(){ 
     if(!this.readyState||this.readyState=='loaded'||this.readyState=='complete'){ 
      $('div').draggable(); 
      $('div').resizable(); 
      $('div').css({'border-style':'dashed','border-width':'3px','border-color':'black','background':'#00ccFF'}); 
     } 
     } 
     ; 
    } 
    } 
    ; 
} 
)(); 

這是同樣的書籤與白的空間壓縮淨化,以備使用:

javascript:(function(){var s1=window.document.createElement('script');s1.setAttribute('src','http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js');window.document.body.appendChild(s1);var s2=window.document.createElement('script');s2.setAttribute('src','http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/jquery-ui.min.js');window.document.body.appendChild(s2);s1.onload=s1.onreadystatechange=function(){if(!this.readyState||this.readyState=='loaded'||this.readyState=='complete'){s2.onload=s2.onreadystatechange=function(){if(!this.readyState||this.readyState=='loaded'||this.readyState=='complete'){$('div').draggable();$('div').resizable();$('div').css({'border-style':'dashed','border-width':'3px','border-color':'black','background':'#00ccFF'});}};}};})(); 

參考文獻:

  • 我發現了以下網站版本Ÿ有助於提高可讀性和寫作的bookmarklet:subsimple.com
  • 也爲測試jsfiddle.net證明非常有幫助,而在旅途