JS 点击按钮复制

14 min read
      let that = this
      let txa = document.createElement('textarea')
      let txval = 'SN:' + that.sn1 + '\n' + 'MAC:' + that.mac1 + '\n' + 'IMEI:' + that.imei1 + '\n' + 'PORT:' + that.port1
      // console.log('copy val:', txval)
      txa.value = txval
      document.body.appendChild(txa)
      txa.select()
      let res = document.execCommand('copy')
      document.body.removeChild(txa)
      console.log('copy success')