//1.在body标签中添加事件
<body οnkeydοwn="keyLogin()">
//登录
<!-- 登录页面 -->
<div class="card border-0 shadow card--login" id="login">
<div class="card-body">
<h2 class="card-title">欢迎登录!</h2>
<form id="loginForm">
<div class="form-group">
<input class="form-control" type="text" placeholder="用户名" required="required" name="userName" id="username" autocomplete="off">
</div>
<div class="form-group">
<input class="form-control" type="password" placeholder="密码" required="required" id="password" name="password" autocomplete="off">
</div>
<div class="form-group">
<label>
<input class="form-control" placeholder="验证码" id="checkCode" autocomplete="off" autocomplete="off" name="checkCode">
</label>
<label>
<img alt="" src="<%=request.getContextPath()%>/CheckCodeServlet" οnclick="changeValidate(this)">
</label>
</div>
<p><a href="<%=request.getContextPath()%>/forgetPass.jsp" data-target="forget">忘记密码?</a></p>
<button class="btn btn-lg" type="button" οnclick="login()">登录</button>
</form>
</div>
<button class="btn btn-back js-btn" data-target="welcome"><i class="fas fa-angle-left"></i></button>
</div>
<script type="text/javascript">
// 敲回车实现登录
function keyLogin(){
if (event.keyCode==13) //回车键的键值为13
login(); //调用登录按钮的登录事件
}
</script>
js如何敲回车实现登录功能
最新推荐文章于 2024-08-27 14:54:05 发布