原生js实现点击复制功能
更新:HHH   时间:2023-1-7


  1. 代码:
    <input type="text">
    <button>复制</button>
    <script>
    var input = document.getElementsByTagName('input')[0]
    var button = document.getElementsByTagName('button')[0]
    button.onclick = function(){
        input.value = "hello world"
        input.select()
        document.execCommand("copy")
    }
    </script>
  2. 效果:

  3. execCommand常用方法:
    cut
    delete
    copy
返回web开发教程...