Javascript 生成带DOM复制到剪贴板的内容

    createCopy(id) {
      var text = document.getElementById(id);
      if (document.body.createTextRange) {
          var range = document.body.createTextRange();
          range.moveToElementText(text);
          range.select();
      } else if (window.getSelection) {
          var selection = window.getSelection();
          var range = document.createRange();
          range.selectNodeContents(text);
          selection.removeAllRanges();
          selection.addRange(range);
      } else {
          alert("none");
      }
      document.execCommand('Copy','false',null);
    }

可用Ctrl+V执行复制操作 非常实用!!!

你可能感兴趣的:(Javascript)