zoukankan      html  css  js  c++  java
  • 回车键转tab键

    function enterToTab(event){  
      var e = event ? event : window.event  
      if(e.keyCode == 13){  
         e.keyCode = 9;  
      }  
    }
    <form> 
    <input type="text" id="input1" onkeydown="enterToTab(event);"/> 
    <input type="text" id="input2" onkeydown="enterToTab(event);"/>
    <input type="text" id="input2" onkeydown="enterToTab(event);"/>
    <input type="text" id="input2" onkeydown="enterToTab(event);"/>
    <input type="submit">
    </form> 

    注意:FireFox 的e.which 属性是只读的,不能更改,所以上面的方面只能用于IE浏览器。
    事件,也只能用onkeydown 事件,而不要用onkeypress 事件,因为对于onkeypress 事件,
    event.keyCode(IE) 和 e.which(Firefox) 是读取不到回车键(13)的,所以要使用onkeydown 事件

    下面是jquery 方案,兼容IE 与firefox
    $(document).ready(function(){
        // get only (input:text) tags with class data-entry
        textboxes = $("input:text");
        // now we check to see which browser is being used
        if ($.browser.mozilla) {
            $(textboxes).keypress (checkForEnter);
        } else {
            $(textboxes).keydown (checkForEnter);
        }
    });
    function checkForEnter (event) {
        if (event.keyCode == 13) {
              currentBoxNumber = textboxes.index(this);
            if (textboxes[currentBoxNumber + 1] != null) {
                nextBox = textboxes[currentBoxNumber + 1]
                nextBox.focus();
                nextBox.select();
                event.preventDefault();
                return false;
            }
        }
    }

  • 相关阅读:
    Android开源库
    银行卡的数字检測
    hdu4941 Magical Forest
    android之检測是否有网络
    在Oracle数据库中使用NFS,怎样调优?
    centos+nginx+php-fpm+php include fastcgi_params php页面能訪问但空白,被fastcgi_params与fastcgi.conf害慘了
    漫谈反射
    Android 四大组件学习之BroadcastReceiver二
    【LeetCode】two num 利用comparable接口 对对象进行排序
    扩展功能==继承?
  • 原文地址:https://www.cnblogs.com/weekend001/p/1655766.html
Copyright © 2011-2022 走看看