需要注意的是

xyz2018

这部分不能设置为“display:none”,否则无法实现复制,如果不想展现id="target"的内容可以这样写

#target{

display:block;

height:0px;

opacity: 0;

}

完整代码如下

复制按钮

这是我的微信号

点击复制

$(document).ready(function(){

var clipboard = new Clipboard('#copy_btn');

clipboard.on('success', function(e) {

alert("微信号复制成功",1500);

window.location.href='weixin://';

e.clearSelection();

console.log(e.clearSelection);

});

});

alert弹窗去掉上方网址标题

window.alert = function (name)

{

const iframe = document.createElement('IFRAME');

iframe.style.display = 'none';

iframe.setAttribute('src', 'data:text/plain,');

document.documentElement.AppendChild(iframe); window.frames[0].window.alert(name);

iframe.parentNode.removeChild(iframe);

};

更多推荐

html添加微信号,html代码点击复制微信号并自动打开微信添加好友