javascript複製內容到剪切板/網頁上的複製按鈕的實現:DEMO以下javascript
<!doctype html> <html> <head> <meta charset="utf-8"> <title>複製內容到剪切板</title> <script> function copy(){ document.getElementById("content").select();//選中要複製的內容,這裏用input標籤能夠,用div標籤不行,估計是隻能用表單標籤,具體沒測試過 document..execCommand("Copy"); //執行瀏覽器複製命令 } </script> </head> <body> <input id="content" value="待複製的內容"> <button onClick="copy();">複製</button> </body> </html>