欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

实战!如何在JavaScript中添加点击复制功能(第二部分) - 代码演示

最编程 2024-02-15 08:23:37
...

html部分:

  <button   @click="copy('要复制的文本')">  复制链接  </button>


js部分:

/**复制字符串 */

function copy(str: string) {

      const inputNode = document.createElement("input");

      inputNode.value = str;

      document.body.appendChild(inputNode);

      inputNode.select();

      document.execCommand("Copy");

      ElMessage.success("复制成功");//这是element plus提示用户复制成功的信息提醒,根据自己实际需求加

  document.body.removeChild(inputNode);

}

推荐阅读