最新js实现复制粘贴功能实例
生活随笔
收集整理的這篇文章主要介紹了
最新js实现复制粘贴功能实例
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
功能:實現鼠標點擊復制內容
描述:使用與手機網站、pc等端。
實現點擊復制粘貼功能的代碼實例:
function common_copy(text){if(text.indexOf('-') !== -1) {var arr = text.split('-');text = arr[0] + arr[1];}var textArea = document.createElement("textarea");textArea.style.position = 'fixed';textArea.style.top = '0';textArea.style.left = '0';textArea.style.width = '2em';textArea.style.height = '2em';textArea.style.padding = '0';textArea.style.border = 'none';textArea.style.outline = 'none';textArea.style.boxShadow = 'none';textArea.style.background = 'transparent';textArea.value = text;document.body.appendChild(textArea);textArea.select();try {var successful = document.execCommand('copy');var msg = successful ? '成功復制到剪貼板' : '該瀏覽器不支持點擊復制到剪貼板';alert(msg);} catch (err) {alert('該瀏覽器不支持點擊復制到剪貼板');}document.body.removeChild(textArea);}總結
以上是生活随笔為你收集整理的最新js实现复制粘贴功能实例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【例8】合唱队形(《信息学奥赛一本通第五
- 下一篇: 第十一届蓝桥杯省赛C++组试题 第3题