1
我想在一個寫入Razor的文本框中遵循指令[numericOnly]?MVC 5.0中的AngularJs指令
@Html.TextBoxFor(m => m.salary, new { data_ng_model = "salary" })
app.directive('numericOnly', function() {
return {
restrict: 'A',
require: '?ngModel',
link: function (scope, element, attrs, ngModel) {
if (!ngModel) return;
ngModel.$parsers.unshift(function (inputValue) {
var digits = inputValue.split('').filter(function (s) { return (!isNaN(s) && s != ' '); }).join('');
if (digits.length > 6) {
digits = digits.substring(0, 5);
}
ngModel.$viewValue = digits;
ngModel.$render();
return digits;
});
}
};
});
請推薦任何人..謝謝。
pankajparkar取代優秀!謝謝 – user3560308 2015-04-06 07:03:58