看 :
http://jsfiddle.net/Ty8PG/14/
ko.bindingHandlers.numericValue = {
init : function(element, valueAccessor, allBindingsAccessor) {
var underlyingObservable = valueAccessor();
var interceptor = ko.computed({
read: underlyingObservable,
write: function(value) {
underlyingObservable(rawNumber(value));
}
});
ko.bindingHandlers.value.init(element, function() { return interceptor }, allBindingsAccessor);
},
update : function(element, valueAccessor, allBindingsAccessor) {
element.value = number_format(valueAccessor()(), 2);
}
};
原帖:
https://groups.google.com/forum/#!topic/knockoutjs/gvhJt4iSOLk