操作键盘事件
常用的鼠标事件
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>常用的鼠标事件</title>
</head>
<body>
<script>
document.addEventListener('keyup', function () {
console.log('我弹起了');
})
document.addEventListener('keypress', function () {
console.log('我按下了press');
})
document.addEventListener('keydown', function () {
console.log('我按下了down');
})
</script>
</body>
</html>
键盘事件对象之keyCode属性
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>键盘事件对象之keyCode属性</title>
</head>
<body>
<script>
document.addEventListener('keyup', function (e) {
console.log('up:' + e.keyCode);
if (e.keyCode === 65) {
alert('您按下的a键');
} else {
alert('您没有按下a键')
}
})
document.addEventListener('keypress', function (e) {
console.log('press:' + e.keyCode);
})
</script>
</body>
</html>