js 实现复制到黏贴板(兼容安卓、iOS)
function copyText(text) {
var input1 = document.createElement(“input”);
var currentFocus = document.activeElement;
var head1 = document.getElementById(‘head1’)
head1.appendChild(input1);
input1.readOnly = ‘readonly’;
input1.value = text;
input1.focus();
if (input1.setSelectionRange)
input1.setSelectionRange(0, input1.value.length);
else
input1.select();
try {
var flag = document.execCommand(“copy”);
} catch (eo) {
var flag = false;
}
input1.blur();
head1.removeChild(input1);
currentFocus.focus();
currentFocus.blur();
return flag;
}`