本文介绍了通过按Enter无需提交按钮即可提交angular2提交表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以提交没有提交按钮的表单(通过按Enter键)例子:
Is it possible to submit a form that does not have submit button (by pressing enter)example :
<form [ngFormModel]="xxx" (ngSubmit)="xxxx()">
<input [(ngModel)]="lxxR" ngControl="xxxxx"/>
</form
推荐答案
也许您将 keypress
或 keydown
添加到输入字段并将事件分配给点击进入时将执行提交的功能
maybe you add keypress
or keydown
to the input fields and assign the event to function that will do the submit when enter is clicked
您的模板看起来像这样
<form (keydown)="keyDownFunction($event)">
<input type="text" />
</form
您在类中的功能将如下所示
And you function inside the your class would look like this
keyDownFunction(event) {
if (event.keyCode === 13) {
alert('you just pressed the enter key');
// rest of your code
}
}
这篇关于通过按Enter无需提交按钮即可提交angular2提交表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!