標簽:復制 clipboard url fail 對象 remove 命令 document title
// 復制文本內容
copy(data) {
let url = data;
// #ifdef APP-PLUS
uni.setClipboardData({
data:url,
success() {
uni.showToast({
title: ‘復制成功‘,
icon: ‘none‘,
duration: 2000
});
},
fail() {
uni.showToast({
title: ‘復制失敗‘,
icon: ‘none‘,
duration: 2000
});
}
});
// #endif
// #ifndef APP-PLUS
let oInput = document.createElement(‘input‘);
oInput.value = url;
document.body.appendChild(oInput);
oInput.select(); // 選擇對象;
document.execCommand("Copy"); // 執行瀏覽器復制命令
// 復制成功提示;
uni.showToast({
title: ‘復制成功‘,
icon: ‘none‘,
duration: 2000
});
oInput.remove();
// #endif
},
標簽:復制 clipboard url fail 對象 remove 命令 document title
原文地址:https://www.cnblogs.com/shoolnight/p/15040446.html