Copy text string on click

后端 未结 8 2005
我在风中等你
我在风中等你 2020-11-27 02:31

I spent a good 20 min searching online for this, but couldn\'t find it. What I want is to to be able to copy a text string on click without a button. The text strin

8条回答
  •  广开言路
    2020-11-27 03:24

    Along with copying the text , you also have to make sure that any previously selected component remains selected after copying to clipboard.

    Here's the full code :

    const copyToClipboard = str => {
      const el = document.createElement('textarea');  // Create a