js判断按键内容
<!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=gb2312" />
<title>
test
</title>
</head>
<script>
function check(e){
var e = window.event ? window.event : e;
if(e.keyCode == 9){
alert("You press the \"Tab\" button");
}
}
</script>
<body>
<p>
<input type="text" name="textfield" onkeydown="check(event);" />
</p>
<p>
<input type="text" name="textfield2" />
</p>
</body>
</html>
判断是否按下了“F5”
document.onkeydown = function(e){
var e = window.event ? window.event : e;
if(e.keyCode == 116){
alert("按下了F5")
}
}
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>
test
</title>
</head>
<script>
function check(e){
var e = window.event ? window.event : e;
if(e.keyCode == 9){
alert("You press the \"Tab\" button");
}
}
</script>
<body>
<p>
<input type="text" name="textfield" onkeydown="check(event);" />
</p>
<p>
<input type="text" name="textfield2" />
</p>
</body>
</html>
判断是否按下了“F5”
document.onkeydown = function(e){
var e = window.event ? window.event : e;
if(e.keyCode == 116){
alert("按下了F5")
}
}
|
ASCII码 |
|
|

浙公网安备 33010602011771号