【JavaScript】js 处理复制函数实现

export const copyText = (text: string) => {
  const input = document.createElement('input');
  input.setAttribute('readonly', 'readonly');
  input.setAttribute('value', text);
  document.body.appendChild(input);
  input.select();
  input.setSelectionRange(0, 9999);
  if (document.execCommand('copy')) {
    document.execCommand('copy');
    ElMessage.success('复制成功');
  }
  document.body.removeChild(input);
};

猜你喜欢

转载自blog.csdn.net/IAIPython/article/details/131672944