打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
jqury使用的几个小技巧
1) 检查IE是否是版本6
  1. if ( (jQuery.browser.msie) && (parseInt(jQuery.browser.version) < 7) ) {  
  2.     $('body').prepend('<div class="warning">You are using an old version of Internet Explorer which is not supported.  Please upgrade your browser in order to view this website.</div>');  
  3. }


2) 打开一个打印的窗口

  1. [url=#]Print this page[/url]  
  2. $('a.print').click(function(){  
  3.     window.print();  
  4.     return false;  
  5. })


3) 禁止表单使用回车键 

  1. $("#form").keypress(function(e) {  
  2.   if (e.which == 13) {  
  3.     return false;  
  4.   }  
  5. });


4) 全选和反选checkbox

  1.  <div class="options">  
  2.     [list]  
  3.         [*][url=#]Select All[/url]  
  4.   
  5.         [*][url=#]Reset All[/url]  
  6.   
  7.     [/list]  
  8.   
  9.     <input type="checkbox" id="option1" /><label for="option1">Option 1</label>  
  10.     <input type="checkbox" id="option2" /><label for="option2">Option 2</label>  
  11.     <input type="checkbox" id="option3" /><label for="option3">Option 3</label>  
  12.     <input type="checkbox" id="option4" /><label for="option4">Option 4</label>  
  13. </div>  
  14. $('.select-all').live('click', function(){  
  15.     $(this).closest('.options').find('input[type=checkbox]').attr('checked'true);  
  16.     return false;  
  17. });  
  18.   
  19. $('.reset-all').live('click', function(){  
  20.     $(this).closest('.options').find('input[type=checkbox]').attr('checked'false);  
  21.     return false;  
  22. }); 

5) 平均分各个列
  有的时候,需要在表格中让各个列等分,可以这样

  1. var max_height = 0;  
  2. $("div.col").each(function(){  
  3.     if ($(this).height() > max_height) { max_height = $(this).height(); }  
  4. });  
  5. $("div.col").height(max_height); 


6 将所有的连接用新建窗口打开

  1. $('a[@rel$='external']').click(function(){  
  2.      this.target = "_blank";  
  3. });  
  4.   
  5. /* 
  6.    Usage: 
  7.    [url=http://www.catswhocode.com]catswhocode.com[/url] 
  8. */




本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
复选框 select添加checkbox
纯CSS设置Checkbox复选框控件的样式 | 朽木博客
jQuery 插件试手
一起学Vue之表单输入绑定
checkbox手动样式改变
Jquery实现自定义复选框样式
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服