手记

前端实现复制功能

//

//复制按钮事件
$scope.copy = function(value){
    var oInput = document.createElement('input');
    oInput.value = value;
    document.body.appendChild(oInput);
    oInput.select(); // 选择对象
    var copyText = document.execCommand("Copy"); // 执行浏览器复制命令
    oInput.style.display = 'none';

    //判断是否复制成功,成功弹框提示
    if(copyText){
        var layer=document.createElement("div");
        layer.id="layer";
        layer.innerHTML="复制成功"

        var style=
            {
                background:"#000000",
                color:"#ffffff",
                position:"absolute",
                zIndex:10,
                width:"180px",
                height:"60px",
                lineHeight:"60px",
                textAlign:"center",
                fontSize:"18px",
                borderRadius:"10px",
                opacity: 0.75,
                left:"48%",
                top:"40%"
            }
        for(var i in style)
            layer.style[i]=style[i];
        if(document.getElementById("layer")==null)
        {
            document.body.appendChild(layer);
            setTimeout("document.body.removeChild(layer)",2000)
        }
    }

}


0人推荐
随时随地看视频
慕课网APP