粘贴复制
方法1:? ?
方法二:
方法三:
// 第三種 ios 設(shè)備和 android設(shè)備均正常,但是pc端沒有//定義函數(shù)
window.Clipboard = (function(window, document, navigator) {
var textArea,
copy;
// 判斷是不是ios端
function isOS() {
return navigator.userAgent.match(/ipad|iphone/i);
}
//創(chuàng)建文本元素
function createTextArea(text) {
console.log(text,"text");
textArea = document.createElement('textArea');
console.log(textArea,"textArea");
textArea.innerHTML = text;
textArea.value = text;
console.log(textArea.value,"textArea.value");
document.body.appendChild(textArea);
}
//選擇內(nèi)容
function selectText() {
var range,
selection;
if (isOS()) {
range = document.createRange();
range.selectNodeContents(textArea);
selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
textArea.setSelectionRange(0, 999999);
} else {
textArea.select();
}
}
//復(fù)制到剪貼板
function copyToClipboard() {
try{
if(document.execCommand("Copy")){
Toast("復(fù)制成功!",1000);
}else{
Toast("復(fù)制失敗!請手動復(fù)制!",1000);
}
}catch(err){
Toast("復(fù)制錯誤!請手動復(fù)制!",1000);
}
document.body.removeChild(textArea);
}
copy = function(text) {
createTextArea(text);
selectText(text);
copyToClipboard(text);
};
return {
copy: copy
};
})(window, document, navigator);
//使用函數(shù)
$("#copy").on("click",function(){
var val = $("#textAreas").val();
console.log("val",val)
Clipboard.copy(val);
});
方法四:
?
轉(zhuǎn)載于:https://www.cnblogs.com/lf2019/p/10997666.html
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
- 上一篇: 梦到别人被录取自己落榜是为什么
- 下一篇: 梦到蟒蛇咬自己是什么意思