qinyuanchun

问题描述:

需要实现点击某个按钮,成功复制某条链接,并在浏览器打开

 

 函数封装:


  <div class="copy" @click="copyText(jump_url)">复制</div>
copyText(text) {
      var textarea = document.createElement(\'input\')// 创建input对象
      var currentFocus = document.activeElement// 当前获得焦点的元素
      document.body.appendChild(textarea)// 添加元素
      textarea.value = text
      textarea.focus()
      if (textarea.setSelectionRange) {
        textarea.setSelectionRange(0, textarea.value.length)
      } else { textarea.select() }
      try {
        this.flag = document.execCommand(\'copy\')// 执行复制
      } catch (eo) {
        this.flag = false
      }
      document.body.removeChild(textarea)// 删除元素
      currentFocus.focus()
      return this.flag
    }

 

分类:

技术点:

相关文章: