js获取回车事件

来源:互联网 发布:c语言保存文件格式 编辑:程序博客网 时间:2024/05/02 04:31

如下代码提供了文本框和页面全局获取回车事件的方法



<!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>JS获取回车按事件</title><script>function keydown(){   var event=arguments.callee.caller.arguments[0]||window.event;//调节浏览器兼容   if (event.keyCode == 13){  alert("您在文本框按下了回车键"); }  }  document.onkeydown=function(event){ e = event ? event :(window.event ? window.event : null); if(e.keyCode==13){ //执行的方法  alert('全局检测到了回车'); } } </script></head><body><input  type="text" onkeydown="keydown()"/></body></html>



0 0
原创粉丝点击