通過js實現復制到剪貼板功能

<input type="text" id="content" value=""/>
<button type="button" onClick="copyUrl2()">復制短鏈接</button>
<script>
function copyUrl2(){
    var urlresult=document.getElementById("content");
    urlresult.select(); // 選擇對象
    document.execCommand("Copy"); // 執行瀏覽器復制命令
    alert("已復制好,可貼粘。");
}
</script>
我剛剛測試了一下,代碼可用!

轉載請注明出處 AE博客|墨淵 ? 通過js實現復制到剪貼板功能

發表評論

路人甲

網友評論(0)