場角我想打一個字段,只需要數字和有一個隱含的數據指向。與隱含小數點
例如兩個數字,讓3,450.65,用戶可以鍵入345065,而不是3450.65,我們會自動插入小數。
一個很好的例子是在這裏:http://jsfiddle.net/n6ggtq7a/
不同的是它豐富的代碼,不會維護,似乎這項任務過於複雜。
話又說回來,有這樣plunker:http://plnkr.co/edit/iFnjcq?p=preview
哪些方式完成這項任務,但使用jQuery的。我想完全不用jQuery。
我看着NG-貨幣
<script>
angular.module('currencyExample', [])
.controller('ExampleController', ['$scope', function($scope) {
$scope.amount = 1234.56;
}]);
</script>
<div ng-controller="ExampleController">
<input type="number" ng-model="amount" aria-label="amount"> <br>
default currency symbol ($): <span id="currency-default">{{amount | currency}}</span><br>
custom currency identifier (USD$): <span id="currency-custom">{{amount | currency:"USD$"}}</span>
no fractions (0): <span id="currency-no-fractions">{{amount | currency:"USD$":0}}</span>
</div>
但這需要有人類型的小數點。我覺得這應該存在的地方...我錯過了明顯的東西?
在Plunker的'format'指令並不包含需要jQuery的帶出了jQuery進口和輸入仍然應該工作的任何代碼。 – miqid
@miqid你是對的!感謝您指出了這一點。 – jenryb