Hac*_*ins 4 html javascript safari javascript-events
触发了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>
Run Code Online (Sandbox Code Playgroud)
在OS X 10.8.2上的Chrome 23.0.1271.95上,onbeforepaste仅在用户弹出上下文菜单时触发.
http://help.dottoro.com/ljxqbxkf.php:
在将剪贴板的内容粘贴到文档中之前发生,并提供启用" 粘贴"菜单项的可能性.
右键单击文本框会导致onbeforepaste事件触发,但不会按ctrl- v.
如果它是任何安慰,onpaste事件会在文本实际粘贴之前触发,在我的测试中,所以我只会使用该onpaste事件.
| 归档时间: |
|
| 查看次数: |
2275 次 |
| 最近记录: |