function copyText(data){
let isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
let isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
let textarea = document.createElement('textarea');
textarea.id = "copyTextarea";
textarea.style.width = 0;
textarea.style.height = 0;
document.body.appendChild(textarea);
textarea = document.getElementById('copyTextarea');
textarea.innerHTML = data;
if(isiOS == "ios"){
const range = document.createRange();
range.selectNode(document.getElementById('copyTextarea'));
const selection = window.getSelection();
if (selection.rangeCount > 0) selection.removeAllRanges();
selection.addRange(range);
}else{
textarea.select(); // 选中文本(select()办法对IOS局部版本有效)
}
document.execCommand('copy');
textarea.blur()
document.body.removeChild(textarea);
alert('复制胜利!')
},
发表回复