Blogger Information
Blog 3
fans 0
comment 0
visits 3685
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
javascript实现将文本复制到剪贴板
猿数据
Original
1153 people have browsed it

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <title>Copy_test</title>

    <style type="text/css">

        button,input{padding:30px;}

        input{width: 70%}

    </style>

</head>

<body><center>

<div id="Content">文本内容是是Test</div><br/>

<button onclick="Copy()" ontouchstart="func()">复制</button><br/><br/>

<input type="text">


<script type="text/javascript">

     

    function Copy(str){

          var Content = document.getElementById("Content");

          var str = Content.innerHTML;


          var save = function(e){

            e.clipboardData.setData('text/plain', str);

            e.preventDefault();

          }

          document.addEventListener('copy', save);

          document.execCommand('copy');

          document.removeEventListener('copy',save);

          alert('复制成功')

    }


</script>



    

</body>

</html>

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post