<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>测试实例</title> <script> function myFunction(message) { var input = document.createElement("input"); input.value = message; document.body.appendChild(input); input.select(); input.setSelectionRange(0, input.value.length), document.execCommand(‘Copy‘); document.body.removeChild(input); alert("复制成功", "text"); } </script> </head> <body> <div onclick="myFunction(‘要复制的内容‘)">点我</div> </body> </html>
参考文章:https://blog.csdn.net/Developersq/article/details/100522751
原文地址:https://www.cnblogs.com/junyi-bk/p/11631631.html
时间: 2024-11-06 09:57:30