[英]When I put 'e' character in input type=“number ” the number is put in the field angular
I need to block the 'e' value that I can put in a input type number so this is my html file: 我需要阻止可以输入输入类型编号的'e'值,所以这是我的html文件:
<input type="number" class="form-control" [(ngModel)]="money" name="money" required min="0" step="0.01" >
in my ts class 在我的ts班
money:number;
Anyone can help me? 有人可以帮助我吗? I want block the possibility to insert the value 'e' in input type number. 我想阻止在输入类型编号中插入值'e'的可能性。
You can use the keypress
event on the input to prevent the entering of e
. 您可以在输入上使用keypress
事件,以防止输入e
。 You'll have to create a method as a handler on your Component Class. 您必须在组件类上创建一个方法作为处理程序。
try this: 尝试这个:
preventE(event) {
if (event.which === 101) {
event.preventDefault();
}
}
Template: 模板:
<input
type="number"
class="form-control"
[(ngModel)]="money"
name="money"
required
min="0"
step="0.01"
(keypress)="preventE($event)">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.