前端在页面实现点击复制功能,一般都会使用document.execCommand;虽然现在还能用,但是会提示你即将被废弃,找了一个替代方法,基于Promise,不用像execCommand一样还得选中范围;看了一下兼容性也挺不错的
navigator.clipboard.writeText(value);
navigator.clipboard.writeText(value).then(() => {});
相关文档: Clipboard.writeText()
前端在页面实现点击复制功能,一般都会使用document.execCommand;虽然现在还能用,但是会提示你即将被废弃,找了一个替代方法,基于Promise,不用像execCommand一样还得选中范围;看了一下兼容性也挺不错的
navigator.clipboard.writeText(value);
navigator.clipboard.writeText(value).then(() => {});
相关文档: Clipboard.writeText()