2018年通车的高铁:jqury使用的几个小技巧

来源:百度文库 编辑:偶看新闻 时间:2024/05/05 08:41:52
1) 检查IE是否是版本6
  1. if ( (jQuery.browser.msie) && (parseInt(jQuery.browser.version) < 7) ) {  
  2.     $('body').prepend('You are using an old version of Internet Explorer which is not supported.  Please upgrade your browser in order to view this website.
');  
  • }

  • 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.    
    2.     [list]  
    3.         [*][url=#]Select All[/url]  
    4.   
    5.         [*][url=#]Reset All[/url]  
    6.   
    7.     [/list]  
    8.   
    9.     Option 1  
    10.     Option 2  
    11.     Option 3  
    12.     Option 4  
      
  • $('.select-all').live('click', function(){  
  •     $(this).closest('.options').find('input[type=checkbox]').attr('checked', true);  
  •     return false;  
  • });  
  •   
  • $('.reset-all').live('click', function(){  
  •     $(this).closest('.options').find('input[type=checkbox]').attr('checked', false);  
  •     return false;  
  • }); 
  • 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. */