zoukankan      html  css  js  c++  java
  • js复制功能

    
    
    <div id="cardList">
            <div class="btn" onClick="copy(111)">点击我,复制我</div>
     </div>
    <script type="text/javascript">   
            function copy(str){
                var save = function (e){
                    e.clipboardData.setData('text/plain',str);
                    e.preventDefault();
                }
                document.addEventListener('copy',save);
                document.execCommand("copy");
                alert("复制成功");
            }
    </script>
    
    
    
    <textarea cols="20" rows="10" id="biao1">用户定义的代码区域</textarea>
    <input type="button" onClick="copyUrl2()" value="点击复制代码" />
    <script type="text/javascript">
    function copyUrl2()
    {
    var Url2=document.getElementById("biao1");
    Url2.select(); // 选择对象
    document.execCommand("Copy"); // 执行浏览器复制命令
    alert("已复制好,可贴粘。");
    }
    </script>
    <div cols="20" id="biao1">12345678dddd</div>
    <input type="button" onClick="copyUrl2()" value="点击复制代码" />
    <script type="text/javascript">
        function copyUrl2(){
                var Url2=document.getElementById("biao1").innerText;
                var oInput = document.createElement('input');
                oInput.value = Url2;
                document.body.appendChild(oInput);
                oInput.select(); 
                document.execCommand("Copy"); 
                oInput.style.display='none';
                alert('复制成功');
           }
    </script>
  • 相关阅读:
    传感器仿真平台——数据生成模块(三)
    写一个ES6 的遍历目录函数
    编码风格
    关于DOM事件的一个例子
    WEB DB
    表格资料
    css3 鼠标移入移出效果
    css 3D
    正向代理和反向代理
    FileReader 对象
  • 原文地址:https://www.cnblogs.com/sure2016/p/9518994.html
Copyright © 2011-2022 走看看