關於input/textarea提交內容空格回車轉換問題,以及ng-model去除空格問題


input/textarea提交內容空格回車轉換問題

 

/*my-enter-bind.js*/
/*回車換行顯示轉義*/
'use strict';

angular.module('app')
  .directive('myEnterBind', function() {
    return {
      restrict: 'A',
      require: '?ngModel',
      scope: {
        myEnterBind: '='
      },
      link: function(scope, elem, attrs) {
        var value = scope.myEnterBind;
        var enterValue = value.replace(new RegExp(/\n/g), '<br>');
        var temp = enterValue.replace(new RegExp(/\s/g), '&nbsp;');
        $(elem).html(temp);
      }
    }
  });

將空格回車轉換即可

關於input/textarea默認去除空格 問題

data-ng-trim=“false”屬性


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM