亲测都能使用
webapp
function copyToClip(tt) {
var text= tt;
if(mui.os.android) {
var Context = plus.android.importClass("android.content.Context");
var main = plus.android.runtimeMainActivity();
var clip = main.getSystemService(Context.CLIPBOARD_SERVICE);
plus.android.invoke(clip, "setText", text);
} else {
var UIPasteboard = plus.ios.importClass("UIPasteboard");
var generalPasteboard = UIPasteboard.generalPasteboard();
// 设置/获取文本内容:
generalPasteboard.setValueforPasteboardType(text, "public.utf8-plain-text");
var value = generalPasteboard.valueForPasteboardType("public.utf8-plain-text");
}
mui.toast("复制成功");
}
})
web
// function copyTextToClipboard(text) {
// var textArea = document.createElement("textarea")
//
// textArea.style.position = 'fixed'
// textArea.style.top = 0
// textArea.style.left = 0
// textArea.style.width = '2em'
// textArea.style.height = '2em'
// textArea.style.padding = 0
// textArea.style.border = 'none'
// textArea.style.outline = 'none'
// textArea.style.boxShadow = 'none'
// textArea.style.background = 'transparent'
// textArea.value = text
//
// document.body.appendChild(textArea)
//
// textArea.select()
//
// try {
// var msg = document.execCommand('copy') ? '成功' : '失败'
// alert('复制内容 ' + msg);
// } catch (err) {
// alert('不能使用这种方法复制内容');
// }
//
// document.body.removeChild(textArea)
// }