Native js implements click copy function

  1. Code:
    <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. Effect:
    Native js implements click copy function
    Native js implements click copy function
  3. Common methods of execCommand:
    cut
    delete
    copy

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324655187&siteId=291194637