我想要一个只接受数字的文本框,我需要这个解决方案,无需 html5 支持。
我在自定义指令模板中有文本框。
ng-keypress="Validation($event)"
和
在该指令的 Controller 中,我这样写:
$scope.Validation = function (e) {
//if the letter is not digit then display error and don't type anything
if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
return false;
}
}
但它不起作用,有什么想法吗?
最佳答案
只需在 return false;
之前添加以下行:
e.preventDefault();
这将阻止按键事件传播并取消用户的输入。
关于javascript - angular.js 中文本框的唯一数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32178777/