<div> <span id="copyMy" onmousedown="copyFn(event)" oncontextmenu="doNothing()">右键复制</span> </div> <script> function doNothing() { // 取消右键弹出的菜单 window.event.returnValue = false; return false; } function copyFn(event) { var val = document.getElementById('copyMy'); if (event.button === 2) { // 判断是否是鼠标右键 window.getSelection().selectAllChildren(val); document.execCommand("Copy"); alert("已复制好,可贴粘。"); } } </script>