0 0

js 按回车键,焦点转到下一个。需支持safari20

html中有多个input,type=text,其中onkeydown执行js

<script>
function jump(next){
    var nextInp = document.getElementById(next);
    var loginae=(typeof event!='undefined')?window.event:e;
    if(loginae.keyCode==13)
    {
nextInp.focus();
    }
}
</script>
<input type=text id=1 onkeydown="jump(2)"/>
<input type=text id=2/>
在ie,ff都可以,但在safari下就不可以了。如何实现在safari下也可以呢?
2014年7月24日 15:24

4个答案 按时间排序 按投票排序

0 0

var handler = function(event){
   event = event || window.event;
   if(event.keyCode == 13){
     //xxxxxxx
   }
};

2014年7月25日 10:33
0 0


2014年7月25日 10:32
0 0

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>TEST</title>
<style type="text/css">
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">

</script>
</head>

<body>
<script>
function jump(next){
    var nextInp = document.getElementById(next);
    var loginae=(typeof event!='undefined')?window.event:e;
    if(loginae.keyCode==13)
    {
nextInp.focus();
    }
}
</script>
<input type=text id='1' onkeydown="jump('2')"/>
<input type=text id='2'/>
</body>
</html> tml>

2014年7月25日 09:55
0 0

难道是 event对象的问题?


<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <title>Document</title>
  <script> 
	function jump(next, event){ 
		if(event.keyCode==13) 
		{ 
			document.getElementById(next).focus(); 
		} 
	} 
</script> 

 </head>
 <body>
	<input type=text id="1" onkeydown="jump('2', event)"/> 
	<input type=text id="2" /> 
 </body>
</html>

2014年7月24日 17:52

相关推荐

Global site tag (gtag.js) - Google Analytics