【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);
};

你可能感兴趣的:(javascript,前端,开发语言,ecmascript)