【问题标题】:How to add commas in a Input Number field?如何在输入数字字段中添加逗号?
【发布时间】:2017-01-25 22:17:34
【问题描述】:

简单的问题,但给我带来了一些问题。

我有一个<input type='number'>,我想用逗号显示输入数据。例如,如果用户输入 1500,则该字段必须显示 1,500。

<input type="number" name="valuation_stocks" ng-model="valuation.estimated_stocks">

【问题讨论】:

标签: angularjs html


【解决方案1】:

也许这有帮助

app.directive('format', ['$filter', function ($filter) {
    return {
        require: '?ngModel',
        link: function (scope, elem, attrs, ctrl) {
            if (!ctrl) return;


            ctrl.$formatters.unshift(function (a) {
                return $filter(attrs.format)(ctrl.$modelValue)
            });


            ctrl.$parsers.unshift(function (viewValue) {

          elem.priceFormat({
            prefix: '',
            centsSeparator: ',',
            thousandsSeparator: '.'
        });                

                return elem[0].value;
            });
        }
    };

http://jsfiddle.net/SAWsA/741/

【讨论】:

猜你喜欢
  • 2012-02-27
  • 1970-01-01
  • 1970-01-01
  • 2015-02-03
  • 1970-01-01
  • 2022-09-22
  • 2018-04-04
  • 2017-04-13
  • 2011-09-30
相关资源
最近更新 更多