在回车键prevent表单提交 [英] Prevent form submission on enter key

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

问题描述

我如何prevent的从角提交表单输入密钥?

How can I prevent the enter key from submitting the form in angular?

有没有办法赶上13键和禁用或者设置为无效的形式,除非从按钮提交与x的ID?

Is there a way to catch the 13 key and disable it or set the form as invalid unless submitting from a button with ID of x?

感谢

推荐答案

既然你反正NG-点击,你也可以使用<按钮式=按钮> ,即使窗体标记内。按钮元素的默认行为是 TYPE =提交,这是您要prevent什么。所以,没有必要的JavaScript在所有!

Since you have ng-click anyways, you could also use <button type="button">, even inside the form tag. The default behaviour of the button element is type="submit", which is what you want to prevent. So, no javascript needed at all!

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

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