将文本链接复制到剪贴板

时间:2021-01-26 20:16:23

标签: reactjs jsx

我有将浏览器的 url 复制到剪贴板的功能:

    const preCopy = "Copy Link"
    const postCopy = "Copied Link"

    function copyURI(evt) {
        evt.preventDefault()
        navigator.clipboard.writeText(evt.target.getAttribute("href")).then(
            () => {
                evt.target = postCopy
                setTimeout(() => {
                    evt.target = preCopy
                }, 30000)
            },
            () => {}
        )
    }

我想在单击此文本链接时在此处实施此操作:

    <text>
        "Copy Link"
    </text>

这是可能的还是我需要一个按钮?我怎么能做到这一点?谢谢

0 个答案:

没有答案
相关问题