Home > front end >  Js is copied to the clipboard onclick (text, context) direct copy
Js is copied to the clipboard onclick (text, context) direct copy

Time:12-07

The function copyText (text, context=' ') {//text: to copy the content, the context pop-up reminder
Var tag=document. The createElement method (" input ");
The tag. The setAttribute (' id ', 'cp_hgz_input');
The tag value=https://bbs.csdn.net/topics/text;
Document. The getElementsByTagName (' body ') [0]. The appendChild (tag);
Document. The getElementById (' cp_hgz_input '). The select ();
Document. ExecCommand (' copy ');
Document. The getElementById (' cp_hgz_input). Remove ();
If (the context==' ') {alert (' copy success ')} else {alert (context)}
}

CodePudding user response:

You put up a code problem is what??????

CodePudding user response:

Js not achieve them this way, can only use CTRL + C

CodePudding user response:

Do you want to do after the click event is triggered, use js to get into a tag value, then this value is assigned to another tag, pop-up bounced after successful?

CodePudding user response:

A clipboard. Js plug-in support for Google,
  • Related