【发布时间】:2018-10-22 01:23:47
【问题描述】:
我有一个输入字段,并且使用 JavaScript 和 React,我将该字段限制为仅限数字:
HTML:
<input type="number" name="worth" id="worth-Valueofproperty-undefined-39916" style="padding: 0px; position: relative; width: 100%; border: none; outline: none; background-color: rgba(0, 0, 0, 0); color: rgba(0, 0, 0, 0.87); cursor: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; font-family: inherit; opacity: 1; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); height: 100%;">
JS:
validateValue(e) {
return (
e.target.value = e.target.value.replace(/[^0-9,.]/, '')
);
}
这很好用,但现在我想在输入中添加逗号以对数百、数千等进行分组。
例如:
1000 -> 1,000
100000 -> 100,000
100000000 -> 100,000,000
我该怎么做?
【问题讨论】:
-
你有任何例子吗?谢谢
-
“添加[逗号]”是指将“1000”转换为“1,000”和“10000000”转换为“10,000,000”吗?
-
如果@ChrisForrence 是正确的,请检查此page。
-
谢谢我尝试了这段代码,但我无法实现它,我已经编辑了我输入的 html 以防万一?谢谢你的帮助
标签: javascript reactjs