移动端 点击 复制到剪贴版

时间:2022-05-16 07:01:21

$(‘.copy‘).click(function(){
  var text=$(this).prev().children().text()
  const input = document.createElement(‘input‘);
  input.setAttribute(‘readonly‘,‘readonly‘);
  input.setAttribute(‘value‘,text);
  document.body.appendChild(input);
  input.setSelectionRange(0, 9999);
  if (document.execCommand(‘copy‘)) {
    input.select()
    document.execCommand(‘copy‘);
  }
  document.body.removeChild(input);
  $(‘.clipBoard_notice‘).css(‘display‘,‘block‘)
  clearTimeout(this.delay)
  this.delay=setTimeout(function(){
    $(‘.clipBoard_notice‘).css(‘display‘,‘none‘)
  },2000)
})