JS -实现复制功能

点击调用函数

copy = obj => {
    if (!document.queryCommandSupported('copy')) {
      throw new Error('document.execCommand method not support copy command');
    }
    const input = document.createElement('input');
    input.style.cssText = 'display: block;opacity: 0;position: absolute;left: -10000px;top: -10000px;z-index: -1;width: 1px;height: 1px;'
    document.body.appendChild(input);
    input.value = obj;
    input.select();
    document.execCommand('copy');
    document.body.removeChild(input);
    message.success('复制成功');
  };

你可能感兴趣的:(JS)