function copyContent(elementText) {
// 动态创建 input 元素
var aux = document.createElement("input");
// 获得需要复制的内容
aux.setAttribute("value", elementText);
// 添加到 DOM 元素中
document.body.appendChild(aux);
// 执行选中
// 注意: 只有 input 和 textarea 可以执行 select() 方法.
aux.select();
// 获得选中的内容
var content = window.getSelection().toString();
// 执行复制命令
document.execCommand("copy");
// 将 input 元素移除
document.body.removeChild(aux);
}
js粘贴
最新推荐文章于 2024-07-15 23:23:20 发布