Use js to realize the code of click and copy function

Use js to realize the code of click and copy function

<!doctype html>
<html>
 
    <head>
        <meta charset="utf-8">
        <title>点击复制功能的实现</title>
    </head>
 
    <body>
        <script type="text/javascript">
            function copyUrl2() {
     
     
                var Url2 = document.getElementById("qipa250");
                Url2.select(); // 选择对象 
                document.execCommand("Copy"); // 执行浏览器复制命令 
                alert("已复制好,可贴粘。");
            }
        </script>用户定义的代码区域
        <!--  <textarea cols="20" rows="10" id="qipa250">www.qipa250.com</textarea>
  -->
        <input type="text" id="qipa250" value="http://www.qipa250.com">

        <input type="button" onClick="copyUrl2()" value="点击复制代码" />
    </body>
 
</html>

Guess you like

Origin blog.csdn.net/guo_qiangqiang/article/details/113433245