这里有段代码点击按钮 复制input中的内容,但是在项目中不太适合我。 于是我参考了:https://www.jianshu.com/p/13442dc61e06 12345678910111213141516171819202122 <textarea id="copy"></textarea> <div class="wrap"> <p id="content">楼观岳阳尽,川迥洞庭开。雁引愁心去,山衔好月来。</p><br /> <button id="btn">拷贝</button> </div> <script type="text/javascript"> //处理按钮点击事件 var btn = document.getElementById('btn'); btn.onclick = function(){ //获取p节点的文本 […]
(more...)
点击按钮 复制input中的内容,也就是在input旁边加个按钮,把input的内容复制。 12345678910<input type="text" id="input" readonly value="点击按钮复制此文本!!"></input> <button onclick="onCopy()">复制内容</button> <script> function onCopy() { document.getElementById('input').select() document.execCommand('Copy') document.getElementById('input').blur() } </script> 这个代码我是在网上找的,参考的这个https://blog.csdn.net/ZGH_77733/article/details/126468057 但是在我的项目中有点问题,点击按钮虽然能复制但是会刷新页面…… 于是做了一个小更改如下。 12345678910<input type="text" id="inputid" readonly value="点击按钮复制此文本!!"></input> <input type="button" onclick="onCopy()" value="复制按钮"> <script> function onCopy() { document.getElementById('inputid').select() document.execCommand('Copy') document.getElementById('inputid').blur() […]
(more...)