Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 仅在粘贴时修剪_Javascript_Angularjs - Fatal编程技术网

Javascript 仅在粘贴时修剪

Javascript 仅在粘贴时修剪,javascript,angularjs,Javascript,Angularjs,如何仅在ng paste==true上实现修剪。我的意思是,当输入的长度超过maxlength=“x”(使用普通类型)时,什么也不会发生,但当用户将某个内容粘贴到输入中(超过maxlength x)时,将触发修剪,并将输入修剪为x maxlength。在html中: <input ng-paste="trim(20)" ng-model="val" ng-init="paste=false" placeholder='paste here'> 在Chrome中,默认情况下它会这样

如何仅在ng paste==true上实现修剪。我的意思是,当输入的长度超过maxlength=“x”(使用普通类型)时,什么也不会发生,但当用户将某个内容粘贴到输入中(超过maxlength x)时,将触发修剪,并将输入修剪为x maxlength。

在html中:

<input ng-paste="trim(20)" ng-model="val"  ng-init="paste=false" placeholder='paste here'>

在Chrome中,默认情况下它会这样做@Enigram在所有浏览器中都是这样的,这可能是他想要的。从我阅读的方式来看,他只希望在用户粘贴时强制执行maxlength,并希望在用户键入时超过maxlength。@rgvassar您是对的,当满足maxlength时,这不是本机ng修剪。不幸的是,它无法使用。它仅在粘贴之前键入文本时修剪文本。
$scope.trim = function(maxLength) {
    $scope.val = $scope.val.substring(0, maxLength);
};