美文网首页
js复制粘贴

js复制粘贴

作者: 卡农me | 来源:发表于2017-08-17 08:45 被阅读7次
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>Document</title>
</head>
<body>
    <div>
        <h1 class="text" id="aa">要复制的内容</h1>
        <input type="text" id="bb" style="display: none;"></input>
    </div>
    
    <button id="btn">点击按钮</button>
</body>
<script>
    document.getElementById('btn').addEventListener('click',function(){
        var copyValue = document.getElementById("aa").innerText;
        var inputText=document.getElementById("bb");
        inputText.style.display = 'block';
        inputText.value = copyValue;
        inputText.select();// 选择对象
        document.execCommand("Copy");// 执行浏览器复制命令
        inputText.style.display = 'none';
    })
</script>
</html>

2.ZeroClipboard插件

相关文章

网友评论

      本文标题:js复制粘贴

      本文链接:https://www.haomeiwen.com/subject/bnhgrxtx.html