<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<input type="text">
<script>
const input = document.querySelector('input')
input.addEventListener('keyup',function(e){
//对象.key:可以知道用户按下了哪个键
if(e.key === 'Enter'){
console.log('按了回车键')
}
})
</script>
</body>
</html>
11-事件对象
最新推荐文章于 2024-06-16 18:09:06 发布