js 實現複製剪切

https://www.bbsmax.com/A/GBJrejw3z0/

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>copy</title>
</head>
<body>
<span id='copy'>複製哈哈哈哈啊哈哈</span>
<button id='btn'>複製</button>
</body>
<script type="text/javascript">
    function copyText()
    {
        var Url2=document.getElementById("copy").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('複製成功');
    }
    document.getElementById('btn').onclick = function() {
        copyText()
    }
</script>
</html>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章