[英]I want my form to progress when you hit the enter key
my website uses a password to progress. 我的网站使用密码进行进度。
however i would like the form to work when hitting the enter key 但是我想在按回车键时使用表格
as it is much easier than moving the mouse 因为它比移动鼠标要容易得多
here is the current code for the form: 这是表格的当前代码:
<form name="login" style="margin: 0px">
<INPUT TYPE="text" NAME="pass" size="17" onKeyDown="if(event.keyCode==13) event.keyCode=9;" style="width: 152px; margin: 5px;"><br >
<input type="button" value="Enter" style="width : 150px; margin: 3px" onClick="TheLogin(this.form)" >
</form>
Thanks, Tom 谢谢汤姆
Add input type="submit"
instead of button
. 添加input type="submit"
而不是button
。 Later use onsubmit
event to catch it. 以后使用onsubmit
事件来捕获它。
只需将“提交”按钮设置为“提交”,就不需要javascript。
<input type="submit" value="enter"/>
在表单中按下Enter的默认操作是调用第一个提交按钮,因此您只需要
<input type="submit" value="enter"/>
You can either use an input type of "Submit" and that will capture that event. 您可以使用输入类型“ Submit”(提交),它将捕获该事件。 Or, you can do something like this: 或者,您可以执行以下操作:
$('body').keydown(function (event) {
if (event.keyCode == 13) {
alert('Enter key pressed');
}
});
IMPORTANT UPDATE 重要更新
DONT use javascript as a medium to verify password and DONT DONT DONT include your password inside your html in a <script>
tag! 不要使用javascript作为验证密码的媒介,不要不要将您的密码包含在html中的<script>
标签中!
Password verification should ONLY be done server-side! 密码验证只能在服务器端进行!
POST
method in your form and not GET
在表单中使用POST
方法而不是GET
<form name="login" style="margin: 0px;" method="post"> <input type="password" name="pass" size="17" style="width:152px;margin:5px;"> <br > <input type="submit" value="Enter" style="width:150px;margin:3px;"> </form>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.