js复制文本到剪贴板
2024-7-11 16:11:24 Author: www.yanglong.pro(查看原文) 阅读量:1 收藏

https://developer.mozilla.org/zh-CN/docs/Web/API/Clipboard/writeText


    function copyText(text) {
        if (navigator.clipboard) {
            navigator.clipboard.writeText(text).then(
                function () {
                    /* clipboard successfully set */
                },
                function () {
                    /* clipboard write failed */
                },
            );
        } else {
            let oInput = document.createElement('input');
            oInput.value = text;
            document.body.appendChild(oInput);
            oInput.select();
            document.execCommand("Copy");
            oInput.className = 'oInput';
            oInput.style.display = 'none';
        }
    }

    function oCopy(text) {
        copyText(text)
        layer.msg('复制成功!')
    }

文章来源: https://www.yanglong.pro/js%e5%a4%8d%e5%88%b6%e6%96%87%e6%9c%ac%e5%88%b0%e5%89%aa%e8%b4%b4%e6%9d%bf/
如有侵权请联系:admin#unsafe.sh