08
2010

每个jQuery开发人员必须知道的5个小技巧

jQuery是个非常优秀的框架。

下面是5个小技巧

1.禁用右键菜单

  1. $(document).ready(function(){
  2.     $(document).bind("contextmenu",function(e){
  3.         return false;
  4.     });
  5. });

2.让字体闪烁

  1. jQuery.fn.flash = function( color, duration )
  2. {
  3.     var current = this.css( 'color' );
  4.     this.animate( { color: 'rgb(' + color + ')' }, duration / 2 );
  5.     this.animate( { color: current }, duration / 2 );
  6. }
  7.  
  8. $( '#someid' ).flash( '255,0,0', 1000 );

3.准备文档替换方案

  1. $(function(){
  2.     //document is ready do something
  3. });

4.检测browser

  1. // Safari
  2. if( $.browser.safari )
  3. {
  4. //do something
  5. }
  6.  
  7. //Above IE6
  8. if ($.browser.msie && $.browser.version > 6 )
  9. {
  10. //do something
  11. }
  12.  
  13. // IE6 and below
  14. if ($.browser.msie && $.browser.version <= 6 )  { //do something } // Firefox 2 and above if ($.browser.mozilla && $.browser.version >= "1.8" )
  15. {
  16. //do something
  17. }

5.检查存在的元素

  1. if ($("#someDiv").length) {
  2.     //yes it does ,do something
  3. }

原文:5 useful jquery tricks every web developer should know

相关日志

如转载请注明:转自Nffish's Blog [ http://nffish.com ]

本文链接地址:http://nffish.com/archives/344

Written by Nffish in: jQuery | 标签:

评论暂缺 »

RSS feed for comments on this post. TrackBack URL


Leave a Reply

Powered By Wordpress Theme AEROTRONIC |
除非另有声明,本网站采用知识共享“署名 2.5 中国大陆”许可协议授权。