h5 + copy text to pasteboard

mui (document) .on ("tap", ".tuijian", function () {
// var parent = $ (this) .parents ('. one_kuai')
var textBox = $ ("# reward_code"). text ( )
// Initial copy method
console.log (textBox)
copy_fun (textBox);
})
// Copy method
function copy_fun (copy) {// The parameter copy is the text content to be copied
console.log (" Copyed ")
mui. plusReady (function () {
// judge whether it is Android or ios
if (mui.os.ios) {
// ios
var UIPasteboard = plus.ios.importClass ("UIPasteboard");
var generalPasteboard = UIPasteboard.generalPasteboard ();
// Set / get text content:
generalPasteboard.plusCallMethod ({
setValue: copy,
forPasteboardType: "public.utf8-plain-text"
});
generalPasteboard.plusCallMethod({
valueForPasteboardType: "public.utf8-plain-text"
});
mui.toast ("Successfully copied to clipboard");
} else {
// 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", copy);
mui.toast ("has been successfully copied to the clip Board ");
}
});
}

 

Guess you like

Origin www.cnblogs.com/lishuang2243/p/12695967.html