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>