修改全局复制方法
This commit is contained in:
@@ -20,11 +20,23 @@ function goTologin() {
|
||||
function copyToClipboard(text) {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
navigator.clipboard.writeText(text).then(() => {
|
||||
resolve()
|
||||
}).catch((err) => {
|
||||
reject()
|
||||
});
|
||||
const textareaEle = document.createElement("textarea");
|
||||
document.body.appendChild(textareaEle);
|
||||
// 2. 将需要复制的文本传入输入框, 并调用 select 方法, 选中输入框中文本
|
||||
textareaEle.value = text;
|
||||
textareaEle.select();
|
||||
textareaEle.readOnly = 'readOnly';
|
||||
// 3. 调用复制选中文本的方法
|
||||
document.execCommand('copy');
|
||||
// 4. 销毁输入框
|
||||
document.body.removeChild(textareaEle);
|
||||
resolve()
|
||||
|
||||
// navigator.clipboard.writeText(text).then(() => {
|
||||
// resolve()
|
||||
// }).catch((err) => {
|
||||
// reject()
|
||||
// });
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user