我在contentEditable div上使用contentEditable,而不是输入类型的文本。但是,我无法以这个link.中提到的方式获取粘贴的内容--我在ngPaste的处理程序中总是没有定义。下面是代码:
HTML:
<div contentEditable="true" ng-paste="stripHtml($event.clipboardData.getData('text/plain'))">
</divJS:
scope.stripHtml = function(content) {
console.log(content); //this is always undefined
}我做错了什么?如何获取粘贴的内容?
发布于 2016-01-18 11:23:38
下面的代码(从Sergey的修改)工作在Windows平台,Firefox 43.0.4,Chrome 47.0.2526.111米,而不是在IE11.0.9中。
<!DOCTYPE html>
<html>
<head>
<style>
.editable {
background: white;
height: 55px;
border: 2px solid blue;
width: 55%;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.js"></script>
<script>
var myApp = angular.module('myApp', []);
myApp.controller('sampleController', function($scope) {
$scope.stripHtml = function(content) {
alert(content);
console.log(content);
};
});
</script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>AngularJS ng-paste within ContentEditable Div</title>
</head>
<body ng-app="myApp">
<div ng-controller="sampleController">
<div class="editable" contentEditable="true" ng-paste="stripHtml($event.clipboardData.getData('text/plain'))"></div>
</div>
</body>
</html>https://stackoverflow.com/questions/34853139
复制相似问题