简体   繁体   English

如何在文本框中输入的所有 0-9 数字之前显示一个零?

[英]How to show a zero before the all 0-9 numbers that input in the textbox?

Here is the Example这是示例

  <div>
    <input class="timepic" type="number"><label style="font-size: 12px;color: black;">HH</label>
    <input class="timepic" type="text"><label style="font-size: 12px;color: black;">MM</label>
    <input class="timepic" type="text"><label style="font-size: 12px;color: black;">SS</label>
  </div>

在此处输入图像描述

  • SO i want to add 00,01,02,03....... in the textbox.所以我想在文本框中添加 00,01,02,03.......。 I expecting a answer related to the angular component.我期待与 angular 组件相关的答案。

- Importent................... - 重要......

If i type a number in the textbox number must be 00,01,02... like this without focusOut in the textbox, As well as if i use up and down arrows in the text box numbers must be 00,01.02........如果我在文本框中键入一个数字,数字必须是 00,01,02... 像这样在文本框中没有 focusOut,以及如果我在文本框中使用向上和向下箭头,数字必须是 00,01.02... ......

You can use the events (change) , (keypress) or (ngModelChange) if you are using a model.如果您使用的是 model,则可以使用事件(change) 、 (keypress (keypress)(ngModelChange) Research a bit about each one to use the best option for you.研究一下每一个,以使用最适合您的选项。 Basically you can process each iteraction and add a 0 before or remove if for example user set other value over 60 (for example).基本上,您可以处理每个迭代并在之前添加 0 或删除,例如,如果用户将其他值设置为 60 以上(例如)。

What I think you're trying to implement here is called an input mask, where data is provided to an input and the displayed value (and perhaps also the underlying stored value) has certain formatting routinely applied to it.我认为您在这里尝试实现的称为输入掩码,其中将数据提供给输入,并且显示的值(可能还有底层存储的值)具有常规应用的某些格式。

There are a bunch of libraries which help in acheiving this in any given JS framework.有很多库可以帮助在任何给定的 JS 框架中实现这一点。

A quick google of Angular libraries for this purpose brings up: https://www.npmjs.com/package/angular-input-masks为此目的快速搜索 Angular 库会出现: https://www.npmjs.com/package/angular-input-masks

There are a few example implementations here too: https://css-tricks.com/input-masking/这里也有一些示例实现: https://css-tricks.com/input-masking/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM