Live2D

js复制文本至剪切板

上代码:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div class="box">
        <input type="text" id="inputA">
        <button onclick="copy()">点击复制输入框内容</button>
    </div>
    <textarea name="" id="" cols="30" rows="10"></textarea>
</body>
<script>
    
    function copy(){
        var input = document.getElementById('inputA')
        input.select()//获取input或textarea 文本信息
        document.execCommand("Copy") //复制内容到粘贴板
    }
</script>
</html>

效果图:

 

posted @ 2022-11-16 14:31  喻佳文  阅读(259)  评论(0编辑  收藏  举报