版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
使用到的资源
<link href="https://cdn.bootcss.com/mui/3.7.1/css/mui.min.css" rel="stylesheet">
<script src="https://cdn.bootcss.com/mui/3.7.1/js/mui.min.js"></script>
第一步:触发点击首先要选中目标内容
function selectText(textbox, startIndex, stopIndex) {
if(textbox.createTextRange) {//ie
var range = textbox.createTextRange();
range.collapse(true);
range.moveStart('character', startIndex);//起始光标
range.moveEnd('character', stopIndex - startIndex);//结束光标
range.select();//不兼容苹果
}else{//firefox/chrome
textbox.setSelectionRange(startIndex, stopIndex);
textbox.focus();
}
}
第二步,选中内容后将选中的内容复制到剪切板上并打开微信
里面使用了mui
function copyNum(){
var NumClip=document.getElementById("header_wx");
var NValue=NumClip.value;
var valueLength = NValue.length;
selectText(NumClip, 0, valueLength);
if(document.execCommand('copy', false, null)){
document.execCommand('copy', false, null)// 执行浏览器复制命令
var titContent = '您已成功复制微信号,是否立即跳转到微信搜索该微信号,确认?';
var titInfo = '复制成功';
var btnArray = ['否', '是'];
mui.confirm(titContent, titInfo, btnArray, function(e) {
if (e.index == 1) {
var locatUrl = "weixin://";
window.location.href = locatUrl;
}
})
}
}
html
<p class="header_info">微信号<input readonly="readonly" id="header_wx" value="15510750980"></input></p>
先这样,能实现点击复制然后跳到微信了