function copyToClipboard(oElement, value) {
    var aux = document.createElement("input");
    if (oElement) {
        var content = oElement.innerHTML || oElement.value;
    }
    var _content = value || content;
    aux.setAttribute("value", _content);
    document.body.appendChild(aux);
    aux.select();
    document.execCommand("Copy");
    document.body.removeChild(aux);
}

document.execCommand('Copy')支持IE6+、firefox9+、chrome、safari6+。

在angular中的使用方法:

 <i class="copy-icon" uib-popover="点击复制" popover-trigger="'mouseenter'" ng-click="copy_content(null, item.video_id)"></i>

控制器:

 $scope.copy_content = function(oElement, value) {
            copyToClipboard(oElement, value);
            growl.addSuccessMessage("已复制到剪切板", {ttl: bpo_prompt.success});
        };

 

相关文章:

  • 2021-12-12
  • 2021-12-19
  • 2021-09-01
  • 2021-05-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-15
猜你喜欢
  • 2021-12-03
  • 2022-12-23
  • 2021-10-18
  • 2022-12-23
  • 2021-10-01
  • 2021-12-03
相关资源
相似解决方案