<!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>
<style>
body{
height: 4000px;
}
</style>
</head>
<body>
<input type="text">
<script>
// 获取元素
var search = document.querySelector('input');
// 监听元素事件
document.addEventListener('keyup',function(e){
// 判断 键盘是否按的s键 83是返回的ASCLL码值
if(e.keyCode === 83){
// 给文本框设置获得焦点
search.focus();
}
})
</script>
</body>
</html>