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>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)