原生 js 实现点击按钮复制文本


copy(){
  const input = document.createElement('input')
  document.body.appendChild(input)
  input.setAttribute('value'," 你想要复制的内容 ")
  input.select()
  if (document.execCommand('copy')) {
    document.execCommand('copy')
  }
  document.body.removeChild(input)
}

 

posted @ 2019-09-06 17:39  阳光下那抹高傲的轻笑  阅读(386)  评论(0)    收藏  举报