<script src="https://cdnjs.cat.net/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdnjs.cat.net/ajax/libs/clipboard.js/1.7.1/clipboard.min.js"></script> <script> $("body").onclick = copycode(); $("body").attr("id" ,"copy"); $("body").attr("data-clipboard-text" ,"需要复制的内容"); function copycode(){var clipboard = new Clipboard('#copy');clipboard.on('success', function (e){console.log("copy ok");});clipboard.on('error', function (e){console.log("copy error");});} </script>