js如果得知我按了esc键
在一个页面中,只要我按了esc键,就会弹出提示,要如果写js代码
------解决方案-------------------- <html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<title> Dynamically Filling Lists </title>
</head>
<body onload= 'document.getELementsByName( "txtParentID ")[0].value=1 '>
<table width= "200 " border= "1 ">
<tr>
<td> 1
<input type= "checkbox " name= "checkbox1 " value= "j " /> </td>
<td> j </td>
<td> </td>
</tr>
<tr>
<td> 2
<input type= "checkbox " name= "checkbox2 " value= "p " /> </td>
<td> p </td>
<td> </td>
</tr>
<tr>
<td> 3
<input name= "checkbox3 " type= "checkbox " value= "p " /> </td>
<td> p </td>
<td> </td>
</tr>
<tr>
<td> 4
<input type= "checkbox " name= "checkbox4 " value= "j " /> </td>
<td> j </td>
<td> </td>
</tr>
<tr>
<td> 5
<input type= "checkbox " name= "checkbox5 " value= "p " /> </td>
<td> p </td>
<td> </td>
</tr>
<tr>
<td> 6
<input type= "checkbox " name= "checkbox6 " value= "j " /> </td>
<td> j </td>
<td> </td>
</tr>
</table>
<script language= "javascript ">
document.onkeydown=function(){
alert(window.event.keyCode)
if(window.event.keyCode==27){
alert( "ok ")
}else{
alert( "err ")
}
}
</script>
</form>
</body>
</html>
------解决方案-------------------- <html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
<title> 按ESC键弹出对话框 </title>
<script type= "text/javascript ">
function keyPressHandler(event)
{
var e=window.event||event;
var kC=e.keyCode;
if(kC==27) alert( 'You have pressed the esc key! ');
}
</script>
</head>
<body onkeydown= "keyPressHandler(event) ">
<h1> Press the escape key </h1>
</body>
</html>