beforecopy
事件被触发,但beforepaste
事件没有被触发。这是为什么?
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<style type="text/css">#editor{width:300px; height:300px; border: 1px solid black;}</style>
</head>
<body>
<div id="editor" contentEditable="true">editor</div>
<script type="text/javascript">
var elEditor = document.getElementById("editor");
elEditor.addEventListener('beforecopy', function(e){
console.log('beforecopy');
e.preventDefault();
e.stopPropagation();
});
elEditor.addEventListener('copy', function(e){
console.log('copy');
});
elEditor.addEventListener('beforepaste', function(e){
console.log('beforepaste');
e.preventDefault();
e.stopPropagation();
});
elEditor.addEventListener('paste', function(e){
console.log('paste')
});
</script>
</body>
</html>
- 在 JavaScript 中使用粘贴板
- 小提琴链接:http: //jsfiddle.net/BjR9q/