我如何触发 按回车键?
所以,我需要修复一个错误:每当你按下“enter”键时;表单不提交。基本上原因是因为触发表单提交的元素是一个 href...我尝试将其设置为提交,但随后 css 失败,所以我想知道是否有办法使其使用 Enter 键提交?
这是代码:
<div class="login-form-bg">
<form name="login_form" id="login_form" method="post">
<table>
<tr>
<td>{translate id='Game'}Login:{/translate}</td>
<td><input type="text" name="ss_users_pseudo" /></td>
</tr>
<tr>
<td>{translate id='Game'}Password:{/translate}</td>
<td><input type="password" name="ss_users_password" /></td>
</tr>
<tr height="30px">
<td> </td>
<td>
<fb:login-button perms="email" id="facebook-login-button"></fb:login-button>
</td>
</tr>
<tr>
<td> </td>
<td class="checkbox"><label for="request_password">{translate id='Game'}<a href="forgotPassword.php">Request password</a>{/translate}</label></td>
</tr>
<tr>
<td> </td>
<td class="checkbox">{translate id='Game'}Remember me{/translate} <input type="checkbox" name="ss_users_remenber_me" value="1" /></td>
</tr>
</table>
<a href="#" onclick="document.login_form.submit(); return false;" name="connect" id="connect">
<div class="button-action login-button-div">
<span><span><span>
{translate id='Game'}Login{/translate}
</span></span></span>
</div>
</a>
</form>
So, I need to fix a bug: Whenever you hit "enter" key; the form doesn't submit. Basically the cause is because the element that trigger form submit is an href... I tried making it a submit but then the css fails so I was wondering if there is a way to make it submit with enter key?
Here is the code:
<div class="login-form-bg">
<form name="login_form" id="login_form" method="post">
<table>
<tr>
<td>{translate id='Game'}Login:{/translate}</td>
<td><input type="text" name="ss_users_pseudo" /></td>
</tr>
<tr>
<td>{translate id='Game'}Password:{/translate}</td>
<td><input type="password" name="ss_users_password" /></td>
</tr>
<tr height="30px">
<td> </td>
<td>
<fb:login-button perms="email" id="facebook-login-button"></fb:login-button>
</td>
</tr>
<tr>
<td> </td>
<td class="checkbox"><label for="request_password">{translate id='Game'}<a href="forgotPassword.php">Request password</a>{/translate}</label></td>
</tr>
<tr>
<td> </td>
<td class="checkbox">{translate id='Game'}Remember me{/translate} <input type="checkbox" name="ss_users_remenber_me" value="1" /></td>
</tr>
</table>
<a href="#" onclick="document.login_form.submit(); return false;" name="connect" id="connect">
<div class="button-action login-button-div">
<span><span><span>
{translate id='Game'}Login{/translate}
</span></span></span>
</div>
</a>
</form>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
实际上,我找到了一种方法来修复它......我所要做的就是使用 display:none 和visible:false; 进行提交;并且没有任何价值让输入工作......我知道这很奇怪,但我来这里是为了修复错误而不是重新设计代码:(
Actually, I found a way to fix it... all I had to do is make a submit with display:none and visible:false; and no value to make the enter work.... I know it's weird, but I'm here to fix bugs not redesign the code :(
这是 jQuery 的答案。但你明白了。
这将检测从表单中的任何输入中按下的 Enter 键,并将触发表单的
submit()
方法Here's a jQuery answer. But you get the idea.
This will detect the enter key being pressed from within any input in the form and it will trigger the form's
submit()
method您是否尝试过文本框的 onkeyup:
我认为应该有效。还没有测试过。
Have you tried on the onkeyup for the textbox:
I think that should work. Haven't tested it.
尽管正确的方法是使其成为提交按钮并相应地更改 CSS(您可以使提交按钮看起来像链接),但您可以注册一个 javascript 事件来更改 document.location 或使用 form.submit() 提交表单
Tough the right approach would be to make it a submit button and change CSS accordingly (you can make a submit button look like a link), You could register a javascript event that changes document.location or submits a form with form.submit()
好吧,我想我通过两种方式帮助您
1- 当焦点位于 href 时您需要
2- 当焦点位于文档上时您需要 一切都好
,如果您需要 a href 的焦点
并且它位于文档上当你按下回车键时,请点击 a href
抱歉,我是第一篇文章,我是新来的
我希望我能帮忙:)
well i think i got you in 2 ways
1- you need when the focus is on the href
2- you need when the focus is on the document all
well if you need it on the focus of the a href
and if its on the document when ever you press enter click the a href
sorry for the first post iam new here
i hope i can help :)