我需要检测用户是否正在执行粘贴(Ctrl+V和鼠标右键单击)。我能够检测到ctrl+V,但我无法检测到鼠标的复制粘贴。我知道onPaste事件,但我需要在keydown事件下使用它,因为我正在为许多其他键组合编写单独的逻辑。我已经将这个问题压缩到下面的一个较小的代码片段中。如果我提前使用mouse.Thanks复制粘贴,我希望触发相同的警报
$("#txt1").keydown(function(event){
if(event.ctrlKey && event.keyCode == 86){
alert("copy paste detected");
}
}); <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" id="txt1"/>
发布于 2019-02-22 16:56:07
我不知道这个答案是否符合你的要求。也许您可以通过添加oncontextmenu来禁用鼠标右键单击,attribute.which将阻止右键单击-->粘贴操作。
<body oncontextmenu="return false">
text
</body>发布于 2019-02-22 15:07:25
$(document).ready(function() {
$("#txt1").bind({
copy: function() {
$('span').text('copy behaviour detected!');
},
paste: function() {
$('span').text('paste behaviour detected!');
},
cut: function() {
$('span').text('cut behaviour detected!');
}
});
});<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input id="txt1" type="text" size="50" value="Copy, paste or cut message here" />
<br>
<span></span>
https://stackoverflow.com/questions/54821592
复制相似问题