<!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</title>
<style>
</style>
</head>
<body>
<input type="text">
<script>
var search = document.querySelector("input")
//keyup防止按下s时s也会输入到文本框里
document.addEventListener('keyup', function (e) {
if (e.keyCode === 83) {
//文本框获得焦点
search.focus()
}
})
</script>
</body>
</html>
黑马js按键输入案例
最新推荐文章于 2023-09-25 19:58:54 发布