我需要检测用户是否正在执行粘贴(Ctrl V和鼠标右键单击)。我能够检测ctrl V,但我不能检测鼠标复制粘贴。我知道onPest事件,但我需要它在keydown事件下,因为我正在为许多其他键组合编写单独的逻辑。我已经将这个问题浓缩成下面一个较小的代码片段。如果我使用鼠标复制粘贴,我希望触发相同的警报。提前感谢
$("#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"/>
我不知道这个回答是否符合你的要求。也许你可以通过添加onContext菜单来禁用鼠标右键单击attribute.which将阻止右键单击-
<body oncontextmenu="return false">
text
</body>
$(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>