本文介绍了防止按回车键提交表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何防止回车键以角度提交表单?
How can I prevent the enter key from submitting the form in angular?
除非从 ID 为 x 的按钮提交,否则有没有办法捕获 13 键并禁用它或将表单设置为无效?
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-click,你也可以使用 ,即使在表格标签.按钮元素的默认行为是
type="submit"
,这是您想要阻止的.所以,根本不需要 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!
这篇关于防止按回车键提交表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!