Mar*_*thu 13 javascript jquery angularjs
我想使用angularJs在textarea中禁用复制粘贴.我试着用ng-paste这样做,像这样:
控制器:
  angular.module('inputExample', [])
  .controller('ExampleController', ['$scope', function($scope) {
  $scope.val = '1';
  $scope.past = function() {
    console.log("d");
    $scope.val ="  ";
  }
}]);
HTML:
<input ng-paste="past()" ng-model="val" ng-pattern="/^\d+$/" name="anim" class="my-input" />
输入框具有旧数据(初始粘贴数据).
阻塞粘贴第二次工作,也就是说,如果我将数据粘贴到输入框中,数据将会出现,但是在第二次粘贴时,数据将不会粘贴,但旧的数据值不会被删除.
quw*_*quw 30
尝试使侦听FOT的一个指令cut,copy和paste事件,然后防止违约事件采取行动.
app.directive('stopccp', function(){
    return {
        scope: {},
        link:function(scope,element){
            element.on('cut copy paste', function (event) {
              event.preventDefault();
            });
        }
    };
});
通过将属性添加到输入框来使用.
<input stopccp ng-model="val" />
你也可以使用ng-copy,ng-cut并ng-paste指示和直接取消事件.
<input ng-cut="$event.preventDefault()" ng-copy="$event.preventDefault()" ng-paste="$event.preventDefault()" ng-model="val" />
ism*_*tro 19
最简单的方法:
<input ng-paste="$event.preventDefault();" placeholder='You cannot past here'>
在这里工作
你可以这样做
app.controller('MainCtrl', function($scope, $timeout) {....
.......
$scope.past = function() {
   $timeout(function() {
      $scope.val = " ";
   }, 0);
}...
| 归档时间: | 
 | 
| 查看次数: | 22067 次 | 
| 最近记录: |