键盘组合键
2025年4月30日小于 1 分钟
示例代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>键盘组合键</title>
</head>
<body>
<script type="text/javascript">
window.onkeydown = function(e)
{
//console.log(e);
if(e.altKey == true && e.key=='z')
{
alert('123456');
}
if(e.ctrlKey ==true && e.key=='q')
{
alert('sdjkfhdjk');
}
//注意:!!!!只要有shift键就需要将对应的字符改为大写
if(e.shiftKey ==true && e.key=="Q")
{
alert('天气好呢好啊');
}
if(e.altKey &&e.ctrlKey && e.shiftKey && e.key=="W")
{
alert('放假爬长城去!');
}
}
</script>
</body>
</html>