加号 html 输入 type=number [英] plus sign in html input type=number

查看:25
本文介绍了加号 html 输入 type=number的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道是否可以在 html input type=number 字段中添加加号?我有一个场景,用户需要输入一个修饰符值,该值是 +1 到 +10 或 -1 到 -10.我想让用户非常明确地知道他们输入的值会增加结果值.因此,如果在正输入值前加上 + 号,那就太好了.

Does anyone know if it's possible to add a plus sign in a html input type=number field? I have a scenario whereby users need to enter a modifier value which is either +1 to +10 or -1 to -10. I want to make it very explicit to the user that their inputted value increments the resulting value. therefore it would be great if a + sign is prepended to a positive inputted value.

我正在以具有引导样式的 Angular2 反应形式使用此输入.所以欢迎使用 Angular2 指令、boostrap 风格甚至 jquery 解决方案

I'm using this input in an Angular2 reactive form with bootstrap styling. so an Angular2 directive, a boostrap style or even a jquery solution are welcome

到目前为止,我所看到的是在表单控件中添加货币符号或添加 + 和减号按钮来增加和减少值.但这不是我想要的,所以我怀疑这是否可能.

What I've seen so far is about adding currency symbols inside the form control or about adding + and minus buttons to increment and decrement the value. But that's not what I want, so I doubt if this is possible at all.

推荐答案

我认为操作输入是不可能的.负数默认为-",正数无符号.

I don't think it is possible to manipulate the input. the default is a "-" for negative and no sign for positive numbers.

即使您检查了创建 UI 框架,例如:

even if you checked a create UI frameworks like:

Jquery UI、Bootstrap、Angular Material ...

Jquery UI, Bootstrap, Angular Material ...

我想唯一的解决方案是编写您自己的自定义代码.

I guess the only solution is to write your own custom code.

有两种方案可用:

1- 带有文本的输入,操作将在 javascript 中.

1- an input with Text and the manipulating will be in javascript.

2- 在 angular2 中创建一个管道并将其提供给元素.我认为这比第一个容易得多.

2- create a pipe in angular2 and give it to the element. which I think it is much easier than the first one.

这篇关于加号 html 输入 type=number的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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