z轉載 上代碼:(注意只能操做可編輯區域)javascript
<script type="text/javascript"> function copyUrl2() { var Url2=document.getElementById("biao1").innerText; var oInput = document.createElement('input'); oInput.value = Url2; document.body.appendChild(oInput); oInput.select(); // 選擇對象 document.execCommand("Copy"); // 執行瀏覽器複製命令 oInput.className = 'oInput'; oInput.style.display='none';
alert('複製成功'); } </script> <div cols="20" id="biao1">12345678</div> <input type="button" onClick="copyUrl2()" value="點擊複製代碼" /> oInput.setSelectionRange(0, 9999);