1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>document.execCommand</title> </head> <body> <div> <button onclick="cut()">剪贴</button> <button onclick="paste()">粘贴</button> <button onclick="copy()">复制</button> <p id="jsP"> Try to alter this text using the execCommands buttons above You see, in this world there's two kinds of people </p> <textarea name="" id="jsTextArea" cols="30" rows="10"></textarea> </div> <script> function copy() { const copyElement = document.getElementById('jsP'); const textareaElement = document.getElementById('jsTextArea'); textareaElement.innerText = copyElement.innerHTML; textareaElement.select(); document.execCommand('copy'); } function paste() { const copyElement = document.getElementById('jsP'); const textareaElement = document.getElementById('jsTextArea'); textareaElement.innerText = copyElement.innerHTML; textareaElement.select(); document.execCommand('paste'); } function cut() { const copyElement = document.getElementById('jsP'); const textareaElement = document.getElementById('jsTextArea'); textareaElement.innerText = copyElement.innerHTML; document.execCommand('cut'); copyElement.innerHTML = ''; textareaElement.select(); } </script> </body> </html>
|
发表于 2023-02-03 上午 11:56:35
你这个粘贴更本就不是粘贴,明明就是通过js代码把一个框的内容复制到另外一个框