JS复制功能

<a href="javascript:;" onclick="copyText()">复制</a>
<span id="text">222</span><input id="input"/>
function copyText() {
    var text = document.getElementById("text").innerText;
    var input = document.getElementById("input");
    input.value = text;
    input.select();
    document.execCommand("copy");
    alert("复制成功");
}

 

posted @ 2019-07-23 14:14  时光博客  阅读(162)  评论(0编辑  收藏  举报