点击按钮实现复制指定文字的代码

mac2024-03-21  23

<style type="text/css">#input{ background-color:#ffffff; border:none; width:0.1px; height:0.1px;}</style> <script type="text/javascript"> function copyText() { var text = document.getElementById("text").innerText; var input = document.getElementById("input"); input.value = text; // 修改文本框的内容 input.select(); // 选中文本 document.execCommand("copy"); // 执行浏览器复制命令 document.write ("复制成功"); } </script> <p id="text" style="display:none;">微信号是xxxx</p> <input id="input" > <button onclick="copyText()">复制微信号</button>

上面的代码是从网上找的,自己做了下内容隐藏。 本想发下原创连接,但实在找不到。抱歉!

最新回复(0)