js复制到剪切板

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title></title>
    </head>
    <body>
            <input value="12312312312132313131" placeholder="" id="txtContent" disabled="disabled" style="border: none;background: transparent;"/>
            <input type="button" onClick="copyTxt()" value="复制" />
    </body>
    <script type="text/javascript">
    function copyTxt(){
        document.getElementById("txtContent").select(); // 选择对象
        document.execCommand("Copy"); // 执行浏览器复制命令
    }
    </script>
</html>

 

posted @ 2020-07-31 11:51  Mr▪小zhou  阅读(132)  评论(0编辑  收藏  举报