首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ngPaste on contentEditable div

ngPaste on contentEditable div
EN

Stack Overflow用户
提问于 2016-01-18 11:04:08
回答 1查看 547关注 0票数 0

我在contentEditable div上使用contentEditable,而不是输入类型的文本。但是,我无法以这个link.中提到的方式获取粘贴的内容--我在ngPaste的处理程序中总是没有定义。下面是代码:

HTML:

代码语言:javascript
复制
<div contentEditable="true" ng-paste="stripHtml($event.clipboardData.getData('text/plain'))">
</div

JS:

代码语言:javascript
复制
scope.stripHtml = function(content) {
    console.log(content); //this is always undefined
}

我做错了什么?如何获取粘贴的内容?

EN

回答 1

Stack Overflow用户

发布于 2016-01-18 11:23:38

下面的代码(从Sergey的修改)工作在Windows平台,Firefox 43.0.4,Chrome 47.0.2526.111米,而不是在IE11.0.9中。

代码语言:javascript
复制
<!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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34853139

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档