【问题标题】:Input text field(mobile app) which does not allow user to Enter Numeric value using angularjs输入文本字段(移动应用程序),不允许用户使用 angularjs 输入数值
【发布时间】:2015-11-25 07:11:25
【问题描述】:
<input type="text"  
       ng-model="emp.eedKey007" 
       ng-keypress="nonNumericInput($event)" >

移动应用程序的输入文本字段(应用程序正在使用 ionic 和 angularjs ),它与控制器中的 $scope.emp.eedKey007 映射。 我想让这个文本字段不是数字的。如果用户想要插入任何数值,他将无法在 text Field(MOBILE)

中输入
$scope.nonNumericInput = function ($event) {
    console.log("key presed");
    $scope.showFixAlert = function() {
        var alertPopup = $ionicPopup.alert({
            title: $translate('Info'),
            template: $translate('Invalid Input ...')
        });
    };
    var charCode = $event.keyCode;
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {  
        console.log("Character is pressed"); 
    } else {
        $scope.showFixAlert();
        /**/ what code should i need to use here so that i can restrict numeric value inserted in text field.** 
       // in below code i try to replace the numeric  character with blank character. which is assigned in eedKey007 but its not working correctly . I can't blank the textfield on numeric value insertion.
        var StringLang = $scope.emp.eedKey007;
        $scope.emp.eedKey007 = StringLang.replace(StringLang.slice(-1),''); 
    }
}

【问题讨论】:

    标签: javascript angularjs jquery-mobile ionic-framework


    【解决方案1】:

    使用 $event.preventDefault();在你的情况下。它会阻止在输入框中输入数值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-25
      • 2016-03-04
      • 2018-03-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多