简体   繁体   English

当您按下Enter键时,我希望我的表格继续进行

[英]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! 密码验证只能在服务器端进行!

  1. Use POST method in your form and not GET 在表单中使用POST 方法而不是GET
  2. Inputs that are used for password should have type set to password and not text. 用于密码的输入应将类型设置为密码,而不是文本。
  3. Javascript is not needed for default form submit (works with enter). 默认表单提交不需要Javascript(与enter一起使用)。
  4. Change your html into this: 将您的html更改为此:
 <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.

相关问题 当您使用IIFE按下Enter键时,我想显示文本 - I want to display the text when you hit enter using IIFE 当我在文本框上按Enter键时,为什么要提交表单? - Why is my form submitting when I hit enter on a textbox? 为什么当我按下 ENTER 键(并且事件中没有 keyCode)时,表单中的第一个按钮是 onclick? - Why is onclick for the first button in a form triggered when I hit ENTER key (and no keyCode in event)? 当我搜索我的站点并按Enter键时,搜索可以正确执行,但是按按钮时,搜索却没有 - When I search my site and hit the enter key, the search performs correctly, but hitting the button, it does not HTML表单 - 当我点击输入时刷新页面! - HTML form - when I hit enter it refreshes page! 当我在文本框中输入值并点击提交时,我希望使用ajax在文本框下方输入该值 - When i enter value into textbox and hit submit i want that value below the textbox using ajax 当我在表单中按下回车键时如何触发另一个按钮 - How to trigger another button when I press enter key inside my form 当我按下键盘 Enter 键以实现 Web 可访问性时,我需要展开和折叠纯 css 手风琴 - I need to expand and collapse pure css accordion when I hit keyboard Enter Key for web accessibility 当我在 form_for 中的 text_field_tag 之一中按 Enter 时,如何禁用发出 POST 请求 - How to disable making a POST request when I hit Enter in one of text_field_tag in a form_for 当我有按钮而不是提交时如何使用回车键提交表单 - How to submit form with enter key when I have a button, not a submit
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM