如何在书签中嵌入cdn加载jquery和jquery-ui?

时间:2011-01-05 15:11:26

标签: javascript jquery jquery-ui bookmarklet

我找到了在bookmarklet中链接和加载jquery的示例,但是找不到同时加载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>

1 个答案:

答案 0 :(得分: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在旅途中证明非常有用
相关问题