<!DOCTYPE html><head> <title>中英文切換</title> <meta charset="UTF-8"/> <script type="text/javascript" src="jquery-3.3.1.min.js"></script> <script type="text/javascript" src="language.js"></script></head><body><table id="data"> <tr> <td class="copyable"> 姓名:</td> <td class="copyable">張三</td> </tr> <tr> <td> 年齡:</td> <td>18</td> </tr> <tr> <td class="copyable"> 性別:</td> <td class="copyable">男</td> </tr></table><br><p class="copy">copy</p><p class="copy">copy2</p><br><div id="copy-temp"></div></body><script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script><script> $(".copy").click(function () { var $o = $("<textarea rows='10' cols='50'>"); $o.val($(this).text())//填充要複製的文字 $("#copy-temp").append($o) if (copy($o[0])) { $o.remove() alert("複製成功!"); } else { alert("複製失敗,請手動複製"); } }) function copy(obj) { obj.select(); try { if (document.execCommand('copy', false, null)) { document.execCommand("Copy"); return true; } } catch (err) { } return false; }</script>