<!DOCTYPE html>
<html lang="zh">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>网页名称</title>
  <style>


  </style>
</head>
<body>
  
<input type="text" id="search-box" placeholder="搜索...">

<script>


const searchBox = document.getElementById('search-box');
let isFocused = false;

document.addEventListener('keydown', function(event) {
  const keyCode = event.keyCode || event.which;

  // 判断按下的键盘码是否为数字键盘上的斜杠键的键盘码(111表示数字键盘上的斜杠键)
  if (keyCode === 111 && !isFocused) {
    event.preventDefault();
    searchBox.focus();
  }
});

// 当文本框聚焦时将isFocused设置为true,失去焦点时设置为false
searchBox.addEventListener('focus', function() {
  isFocused = true;
});

searchBox.addEventListener('blur', function() {
  isFocused = false;
});




</script>


</body>
</html>