随机显示微信号,并复制跳转微信

Camille ·
更新时间:2024-09-21
· 710 次阅读

之前写过一篇复制微信号并跳转微信的示例,对于固定的一个微信号是可以使用的,但是不能满足多个微信号随机显示并复制跳转的问题。这里补充一下示例。

随机显示微信号,并复制跳转微信 a:link{text-decoration:none;}/* 指正常的未被访问过的链接*/ a:visited{text-decoration:none;}/*指已经访问过的链接*/ a:hover{text-decoration:none;}/*指鼠标在链接*/ a:active{text-decoration:none;}/* 指正在点的链接*/ .wx{ width: 90%; margin-left: 5%; font-size: 18px; color:white; text-align: center; background-color: #ff7f2e; border-radius: 5px; line-height: 40px; } .wx a{ font-size: 18px; color:white; } /*弹窗*/ .tan{ width:80%; height:180px; background-color:#e8e8e8; position:fixed; left:10%; top:40%; display:none; z-index: 200; } .kuang{ height:120px; text-align:center; padding: 20px 0; } .txtcss{ color:red; font-weight:800; font-size:20px; } .copy{ font-size: 16px; float: left; background-color: #5AD700; padding: 5px 20px; margin-left: 25%;color: black; border-radius: 5px; } .copy a{color: white;} .guanbi{ width:20px; height:20px; color:red; margin-top:-130px; }
张三的微信号是,(点击微信号复制)
张三的微信号是,(点击微信号复制)
添加微信了解更多
咨询学费
了解更多
请添加微信:

复制并跳转微信

x
/*点击复制微信号*/ function copywx(){ const range = document.createRange(); range.selectNode(document.getElementById('copy_content')); const selection = window.getSelection(); if(selection.rangeCount > 0) selection.removeAllRanges(); selection.addRange(range); document.execCommand('copy'); alert("复制成功!"); } /*点击出现弹框*/ function showwx(){ var ss=document.getElementById('myshow'); ss.style.display='block'; } /*关闭弹窗*/ function closeshow(){ var ss=document.getElementById('myshow'); ss.style.display='none'; } /*微信号数组*/ var arr_wx=['微信1','微信2','微信3']; var index=0; //进入页面每隔一定时间随机显示微信号 function change(){ var copy_content=document.getElementsByClassName('copy_content'); index=Math.floor(Math.random()*arr_wx.length); for(var i=0;i<copy_content.length;i++){ copy_content[i].innerText=arr_wx[index]; } } change(); setInterval('change()',1000*60);

效果如下,样式可以自己调整
在这里插入图片描述


作者:一只胡萝卜



微信号

需要 登录 后方可回复, 如果你还没有账号请 注册新账号