【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);
};
posted @ 2023-07-11 09:33  努力挣钱的小鑫  阅读(39)  评论(0编辑  收藏  举报