document.execCommand(‘copy’);//实现剪切复制剪切版的主要实现
虽然目前暂时不推荐使用,但是目前也只有这个实现,便还是继续使用
链接:https://developer.mozilla.org/zh-CN/docs/Web/API/Document/execCommand

const copyUrl = (url) => {
const input = document.createElement('input');
document.body.appendChild(input);
input.setAttribute('value', url);
input.select();
if (document.execCommand('copy')) {
document.execCommand('copy');
console.log('复制成功')
}
document.body.removeChild(input);
};
本文介绍了如何通过JavaScript的`document.execCommand('copy')`方法实现剪切复制功能,尽管不推荐但仍是常见手段,通过创建临时input元素来操作剪贴板。
1114

被折叠的 条评论
为什么被折叠?



