Typescript + HTML:如何在输入字段中强制使用大写 [英] Typescript + Html: How to force uppercase in an input field

查看:259
本文介绍了Typescript + HTML:如何在输入字段中强制使用大写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用angular(打字稿),并且在html中有一个模型形式,用户必须在其中插入代码字段和描述字段.

I'm working with angular (typescript) and I have a modelform in html where the user has to insert a code field and a description field.

代码字段必须始终由用户输入,始终使用大写字母.

The code field must always be entered by the user, always in uppercase.

我找到并关注了这个问题: 如何将输入值转换为角度2的大写字母(值传递给ngControl)

I found and followed this question: How to convert input value to uppercase in angular 2 (value passing to ngControl)

,但是用户插入的最后一个字母仍然是小写.. 最基本的是,数据库总是大写(我也限制了4个字符的大小写才能正常工作) 这是我的代码,但是如上所述,它无法正常工作:

but the last letter that the user inserts remains lowercase however .. The fundamental thing is that the database always comes in all uppercase (I also put a limit of 4 characters that works properly) this is my code now, but as written above it does not work properly:

<input type="text" id="code" #code class="form-control" formControlName="code" maxlength="4"
                 (input)="code.value=$event.target.value.toUpperCase()">

有人找到快速,实用且快速的解决方案吗?

has anyone found a quick, functional and fast solution?

谢谢!

推荐答案

您只需在<input>标记中添加oninput="this.value = this.value.toUpperCase()",它将立即将输入字段中的任何输入转换为大写.

You can simply add oninput="this.value = this.value.toUpperCase()" in your <input> tag and it will instantly convert any input in your input field to Uppercase.

这篇关于Typescript + HTML:如何在输入字段中强制使用大写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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