用document.execCommand()复制文本,会发现在安卓上生效,在IOS上不生效
var ele = $(e.target),
codeEle = $('),
u = navigator.userAgent,
isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1;
if (!document.execCommand) {
Util.toast('当前环境不支持复制功能');
return false;
}
if (isAndroid) {
codeEle.select();
var result = document.execCommand('copy');
if (result) {
Util.toast('已经复制到剪贴板');
} else {
Util.toast('复制失败');
return false;
}
} else {
//var input = document.createElement('input');
let input = $(')[0];
input.value = codeEle.val();
input.select();
input.setSelectionRange(0, input.value.length);
document.execCommand('Copy');
//document.body.removeChild(input);
Util.toast('已经复制到剪贴板');
}
用clipboard.js解决IOS复制文本问题