dunke

// 动态创建 input 元素
var aux = document.createElement(\'input\');
// 获得需要复制的内容
if (type) {
aux.setAttribute(\'value\', url);
} else {
aux.setAttribute(\'value\', url);
}
// 添加到 DOM 元素中
document.body.appendChild(aux);
// 执行选中
// 注意: 只有 input 和 textarea 可以执行 select() 方法.
aux.select();
// 获得选中的内容
var content = window.getSelection().toString();
// 执行复制命令
document.execCommand(\'copy\');
// 将 input 元素移除
document.body.removeChild(aux);

分类:

技术点:

相关文章:

  • 2021-10-22
  • 2021-11-09
  • 2021-11-23
  • 2021-11-23
  • 2021-11-23
  • 2021-10-12
  • 2021-11-13
猜你喜欢
  • 2021-11-23
  • 2021-11-23
  • 2021-11-23
  • 2021-11-23
  • 2021-11-23
相关资源
相似解决方案