前言
目前子比主题下载页面没有密码点击复制功能,小伙伴每次都需要手动复制,但是有了复制功能就能免除繁琐的手动复制了,这里就分享出来!放到通用的JavaScript里!
效果图
JavaScript代码
<!--下载页面密码复制-->
if(document.querySelectorAll(".but-download .badg")!=undefined){
const reg = /[a-zA-z0-9]/ig;
const copy = document.querySelectorAll(".but-download .badg");
for (let i = 0; i < copy.length; i++) {
copy[i].index = i;
copy[i].setAttribute("data-toggle", "tooltip");
copy[i].setAttribute("data-original-title", "点击复制");
copy[i].addEventListener("click", copyOperation);
};
function copyOperation() {
var oInput = document.createElement("input");
let text = this.innerText;
text = text.match(reg).join("");
oInput.value = text;
document.body.appendChild(oInput);
oInput.select();
document.execCommand("Copy");
oInput.className = "oInput";
oInput.style.display = "none";
this.setAttribute("data-original-title", "已复制");
};
};
感谢您的来访,获取更多精彩文章请收藏本站。

© 版权声明
THE END
暂无评论内容