Home >Web Front-end >JS Tutorial >A small example of converting Enter to Tab (compatible with IE, Firefox)_javascript skills

A small example of converting Enter to Tab (compatible with IE, Firefox)_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:15:131024browse
复制代码 代码如下:

document.onkeydown=function(e){
  var e=window.event||e;
  var element=e.srcElement||e.target;
  if(e.keyCode==13&&element.type!="submit"&&element.type!="button"&&element.type!="textarea"&&element.type!="reset"){
    if(document.all){
      e.keyCode=9;
    }else{
      getNextInput(element).focus();
      e.preventDefault();
    }
  }
}
function getNextInput(input){
  var form=input.form;
  for(var i=0;i    if(form.elements[i]==input){
      break;
    }
  }
  while(true){
    if(i       if(form.elements[i].type!="hidden"){
        return form.elements[i];
      }
    }else{
      return null;
    }
  }
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn