js复制内容到剪贴板,代码如下:

function copy (text) {  // text是复制文本  // 创建input元素  const el = document.createElement('input')  // 给input元素赋值需要复制的文本  el.setAttribute('value', text)  // 将input元素插入页面  document.body.appendChild(el)  // 选中input元素的文本  el.select()  // 复制内容到剪贴板  document.execCommand('copy')  // 删除input元素  document.body.removeChild(el)  alert('复制成功')}

 

本站提供的所有下载资源均来自互联网,仅提供学习交流使用,版权归原作者所有。如需商业使用,请联系原作者获得授权。 如您发现有涉嫌侵权的内容,请联系我们 邮箱:[email protected]