问题解决了,在网上找了个自定义弹窗的东西,弹窗的时候,用确定按钮做复制,自定义弹窗参考:https://blog.csdn.net/qq_27437967/article/details/70858262
复制到剪贴板代码如下:(窗口有点难看...)
function copyText(str) {
new ShowDiv(str);
}
function ShowDiv(str) {
var _this = this;
this.AppConfirm = document.getElementById("AppConfirm");
if (this.AppConfirm == null) {
this.AppConfirm = document.createElement("div");
document.body.appendChild(this.AppConfirm);
this.AppConfirm.id = "AppConfirm";
}
this.modlueDiv = document.getElementById("modlue");
if (this.modlueDiv == null) {
this.modlueDiv = document.createElement("div");
this.AppConfirm.appendChild(this.modlueDiv);
this.modlueDiv.id = "modlue";
}
this.MyContent = document.getElementById("MyContent");
if (this.MyContent == null) {
this.MyContent = document.createElement("div");
this.MyContent.id = "MyContent";
this.MyContent.className = "MyContent";
this.modlueDiv.appendChild(this.MyContent);
this.MyContent.innerText = "复制成功";
}
this.MyBtn = document.getElementById("MyBtn");
if (this.MyBtn == null) {
this.MyBtn = document.createElement("div");
this.MyBtn.id = "MyBtn";
this.MyBtn.className = "MyBtn";
this.modlueDiv.appendChild(this.MyBtn);
}
this.confirmBtn = document.getElementById("confirm");
if (this.confirmBtn == null) {
this.confirmBtn = document.createElement("button");
this.confirmBtn.id = "confirm";
this.confirmBtn.innerText = "确定"
this.MyBtn.appendChild(this.confirmBtn);
}
this.newMask = document.createElement("div");
this.modlueDiv.style.visibility = "visible";
var clipboard = new ClipboardJS("#confirm", {
text: function () {
return str;
}
})
clipboard.on("success", function (e) {
console.log("ok:")
console.log(e)
clipboard.destroy();
})
clipboard.on("error", function (e) {
console.log("err:")
console.log(e)
clipboard.destroy();
})
//确认按钮
this.confirmBtn.onclick = function () {
_this.CloseDivAndInfoMesg(this);
}
// 创建弹出层 遮罩层 等
if (!document.getElementById("mask") && 1) {
//mask div
this.newMask.id = "mask";
this.newMask.style.position = "absolute";
this.newMask.style.zIndex = "1";
this.newMask.style.width = "100%";
this.newMask.style.height = Math.max(document.body.scrollHeight, document.documentElement.scrollHeight) + 100 + "px";
this.newMask.style.top = "0px";
this.newMask.style.left = "0px";
this.newMask.style.background = "gray";
this.newMask.style.filter = "alpha(opacity=80)";
this.newMask.style.opacity = "0.5";
document.body.appendChild(this.newMask);
}
_this.mask = document.getElementById("mask");
_this.mask.style.visibility = "visible";
}
//点击取消按钮关闭模态框
ShowDiv.prototype.CloseDiv = function () {
this.modlueDiv.style.visibility = "hidden";
this.mask.style.visibility = "hidden";
}
//点击确认按钮关闭模态框,提示增加信息
ShowDiv.prototype.CloseDivAndInfoMesg = function () {
this.CloseDiv();
}