js复制文本到剪贴板

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('复制成功!')
    }