zoukankan      html  css  js  c++  java
  • angular input 去空格

     
    方案一:ng-blur事件,正则去空格
    <input type="tel" id="mobileInpt" class="f14" name="mobile" value="" placeholder="请输入您的手机号" ng-model="vm.mobile" ng-blur="vm.mobileRE($event)" required>
    vm.mobileRE = function($event) {
      var that = $event.currentTarget;
      $(that).val(function(n, c) {
         return c.replace(/(^s*)|(s*$)/g, "");
      });
    }
    
    方案二:指令,keyup事件
    <input type="tel" id="mobileInpt" class="f14" name="mobile" value="" placeholder="请输入您的手机号" ng-model="vm.mobile" space-filter="mobileRE" required>
    angular.module('app').directive('spaceFilter', [function() {
      return {
        require: "ngModel",
        link: function(scope, element, attrs, ngModel) {
          var attr = attrs.spaceFilter;
          if (attr) {
             var dataType = {
              "mobileRE": /s*/g
              }
            var regex = dataType[attr];
          }
          element.bind('keyup', function(value) {
            this.value = this.value.replace(regex, '');
         });
       }
     }
    }])
     
  • 相关阅读:
    2.7 矩阵的秩
    HDU
    HDU
    HDU
    HDU
    HDU
    hdu 5179 beautiful number(数位dp)
    ACdream
    CodeForces
    <a>标签中 href="/" 和 hideFocus="true"
  • 原文地址:https://www.cnblogs.com/xmyun/p/6374112.html
Copyright © 2011-2022 走看看