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>
原文地址:https://www.cnblogs.com/xiaozhou223/p/13408874.html