HTML 中
<input type="text" value="我是要復制的內容" id="copyObj" /> <div onclick="CopyUrl()">點擊復制按鈕</div>
JS中
<script type="text/javascript"> function CopyUrl() { let url = document.querySelector('#copyObj'); url.select(); // 選擇對象 document.execCommand("Copy"); } </script>