使用 javascript 在 Enter 键上提交表单 [英] Submit form on Enter key with javascript

查看:40
本文介绍了使用 javascript 在 Enter 键上提交表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定我在这里做错了什么.我希望回车键和点击按钮一样有效.

I'm not sure what I am doing wrong here. I want the enter key to work as well as clicking the button.

<form action="" method="get" class="priceOptionForm" name="priceOptionForm">
<input name="paypal_email" type="text" value="whatever" id="email"></label>
<a href="javascript:void(0);" class="bluebtn" id="profile_price" style="width:60px;margin-top:5px;">Save all</a>
</form>

推荐答案

试试这个:

document.getElementById('email').onkeydown = function(e){
   if(e.keyCode == 13){
     // submit
   }
};

这篇关于使用 javascript 在 Enter 键上提交表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆