jquery监听ctrl + c 和 鼠标右键“复制”事件
<script type="text/javascript" src="jquery.min.js"></script> <script type="text/javascript"> // 监听 ctrl + c事件 $(document).unbind('keydown').bind('keydown', function(e){ if(e.ctrlKey && e.keyCode == 67) { doSomething(); // 返回false, 防止重复触发copy事件 return false; } }) // 鼠标右键的复制事件 $(document).unbind('copy').bind('copy', function(e) { setTime(); console.log('右键复制 监听成功'); }); function doSomething(){ setTime(); console.log('ctrl + c 监听成功'); } function setTime(){ if(window.localStorage) { let time = localStorage.getItem('time'); time ? time ++ : time = 1; localStorage.setItem('time', time); } } </script>