js常用复制功能

方式一:

//方式一:支持http

let str= "aaaaa" const copyInput = document.createElement('input'); copyInput.value = str; document.body.appendChild(copyInput); copyInput.select(); document.execCommand('Copy');

//方式二:不支持http
let textValue= "aaaaa"
navigator?.clipboard
      ?.writeText(textValue)
      .then(() => {
        message.success('复制成功');
      })
      .catch(() => {
        message.error('复制失败');
      });

  

posted @ 2023-11-03 15:48  风zz  阅读(28)  评论(1编辑  收藏  举报