你的位置:首页 > Java教程

[Java教程]js event 2


js event 2  浏览器兼容

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html>  <head>    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">    <title>事件编程</title>  // js event 键盘方向键         function $(id){             return document.getElementById(id);           }        window.onload = function() {        $('content').onkeydown = function(event) {          if(window.event) {  //ie            var code = window.event.keyCode;          } else {   //w3c            var code = event.keyCode;          }                    switch(code) {            case 37:              alert('向左');            break;            case 38:              alert('向上');            break;            case 39:              alert('向右');            break;            case 40:              alert('向下');            break;          }        }      }    </script>  </head>  <body>    <input id='content' type='text' name='text'>      </body></html>