In diesem Artikel wird die Methode zum Kopieren von Text oder Bildern in die Zwischenablage beschrieben, nachdem Sie auf JS geklickt haben. Der Code ist sehr prägnant und praktisch, und der spezifische Funktionscode lautet wie folgt:
Textcode implementieren:
<table CellPadding = "0" cellpacing = "0"> <tr> <th style = "color: weiß;"> <s: text name = "querylist details"> </s: Text> </tR> <tr> <tr> <TD align = "center"> <textarea name = "InquiryContact1" Id = "Anfragen": "InquiryCont1" ROWS = " Readonly = "Readonly"> </textArea> <div id = "InquiryInfodiv" style = "display: keine </script> </td> </tr> <tr> <td align = "center"> <input type = "button" id = "button" name = "button" value = "coces" onclick = "copyContact ()"/> </td> </tr> </table> <script type = "text/javascript"> var i = 0; Funktion CopyContact () {var contat = document.getElementById ("InquiryContact1"). Wert; window.clipboardData.setData ('text', contat); if (window.clipboardData.getData ('text') == '') {if (i == 1) {alert ("Kopieren, bitte kopieren Sie manuell Strg+C -Verknüpfungsschlüssel!"); } else {alert ("Kopieren Sie fehlgeschlagen, bitte erneut kopieren!"); i = 1; }} else {alert ("Inhalt wurde in die Zwischenablage kopiert!"); }} </script>Kopierbildcode implementieren:
<! DocType html public "-// w3c // dtd html 4.01 transitional // en <title> Title hier einfügen </title> <script sprach = "jscript"> var opopup = window.createpopup (); Funktion ButtonClick (div) {// var div = document.getElementById ('divid'); div.contentable = 'true'; var controlRange; if (document.body.CreateControlRange) {controlRange = document.body.CreateControlRange (); ControlRange.AddElement (Div); ControlRange.execcommand ('Copy'); } div.contentable = 'false'; } </Script> </head> <body> <divid = "divid1"> <img src = "f: /2012070518474964.jpg" onclick = "buttonclick (this)"> </div> </body> </body> </html>Interessierte Leser können den Code selbst testen oder seine Funktionen ändern und verbessern!