onkeydown:键盘按下事件
按键的ASCII:ev.keyCode
是否按下了特定的组合按钮 :
if (ev.altKey == true) {
console.log('您按下了alt键')
} else if (ev.ctrlKey == true) {
console.log('您按下了ctrl键')
} else if (ev.shiftKey == true) {
console.log('您按下了shift键')
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body οnkeydοwn="key();">
</body>
<script>
function key(e){
var ev = e||event
document.title=ev.keyCode
// 判断是否按下了组合按键
if(ev.altKey==true){
console.log('您按下了alt键')
}
else if (ev.ctrlKey == true) {
console.log('您按下了ctrl键')}
else if (ev.shiftKey == true) {
console.log('您按下了shift键')
}
}
</script>
</html>