`
hz_chenwenbiao
  • 浏览: 996200 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

回车事件

    博客分类:
  • JS
阅读更多

监听页面回车事件:

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>test.html</title>

		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="this is my page">
		<meta http-equiv="content-type" content="text/html; charset=UTF-8">

		<script type="text/javascript">
			document.onkeydown = function(e) {
				var ie = navigator.appName == "Microsoft Internet Explorer";
				if (ie) {
					if (event.keyCode == 13) {
						alert("你敲回车!");
					}
				} else {
					if (e.which == 13) {//firefox
						alert("你敲回车!");
					}
				}
			}
		</script>

	</head>

	<body>
		敲敲回车看
	</body>
</html>

 

 

在输入框时监听回车事件:

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>test.html</title>
	
    <script type="text/javascript">
	    function keyListener(e){
	    	var ie=navigator.appName=="Microsoft Internet Explorer";
	    	if(ie){
	    		if(event.keyCode==13) {
	    			alert("你敲回车!");
	    		}
	    	}else{
	    		if(e.which==13) {//firefox
	    			alert("你敲回车!");
	    		}
	    	}
	    }
    </script>

  </head>
  
  <body>
  	<!-- onpaste是粘贴事件 -->
    <input id="tip" type="text" value=""  onkeydown="keyListener(event)" onpaste="return false;" />
  </body>
</html>
 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics