javascript 键盘监听

<script type="text/javascript">
document.onkeydown=function ainy(){
if (window.event.shiftKey)
{
alert("你按了shift键");
var showtext=document.getElementById("showtext");
showtext.innerHTML="此处是按下shit键显示的内容";
}
else if(window.event.ctrlKey)
alert("你按了ctrl键");
//else if(window.event.atlKey)
//alert("你按了atl键");
}
</script>


<body   onkeydown="ainy();">
<div id=showtext></div>

<script type="text/javascript">
document.onkeydown=function() {
if (event.keyCode==13) {
alert("您按了回车键了!");
}
}
</script>

 

你可能感兴趣的:(JavaScript)