js event 2

js event 2,第1张

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>

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/586660.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-12
下一篇 2022-04-12

发表评论

登录后才能评论

评论列表(0条)

保存