js--选中文字复制到剪贴板上

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>点击按钮时将选中文字复制</title>
</head>
<body>
    <h2>我是H2标签</h2>
    <input type="button" onclick="copy()" value="点击后复制鼠标左键选中的文字">
    <input type="text" placeholder="ctrl + v或右键粘贴">
    <script>
        function copy(){
            document.execCommand("Copy"); 
        }
    </script>
</body>
</html>

 

posted @ 2017-07-15 01:45  Tsingtree  阅读(443)  评论(0编辑  收藏  举报