<!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>Document</title>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.js"></script>
</head>
<body>
<div>
<input id="mytext" type="text" name="username" placeholder="请输入搜索内容" maxlength="6">
<button>搜索</button>
</div>
<script>
$('button').click(function () {
alert('搜索成功')
})
$('#mytext').bind('keydown', function (e) {
console.log(e.keyCode);
if (e.keyCode == 13) {
$('button').click();
}
})
</script>
</body>
</html>
效果: