HTML
<div id="layui-m-layer0" class="layui-m-layer layui-m-layer0" style="display: none;" index="0"><div class="layui-m-layershade"></div><div class="layui-m-layermain"><div class="layui-m-layersection"><div class="layui-m-layerchild layui-m-layer-layui-layer-rim layui-m-anim-up"><h3 style="background-color:#8DCE16; color:#fff;">温馨提示</h3><div class="layui-m-layercont"><div> <a href="tel:18331631035"><button type="button" class="layui-btn" id="dia_tel"><i class="layui-icon layui-icon-cellphone"></i> 拨打电话</button></a><button type="button" class="layui-btn layui-btn-warm" onviews="cpy()" id="btn_cpy"><i class="layui-icon layui-icon-login-wechat"></i>复制加好友</button></div></div><div class="layui-m-layerbtn"><span id="xinxioff" type="1" data-spm-anchor-id="181.7850105.0.i1">关闭</span></div></div></div></div></div>
<textarea id="tel_copy" style="visibility: visible;border: 0px; color: #FFFFFF;opacity: 0;" readonly="readonly">18331631035</textarea>
<span id="data-copy" style="-webkit-user-select: text; background-color: #f2f3f4;color: #f2f3f4;opacity:0.1;">18331631035</span>
JS
function cpy()
{
if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) { //ios
var copyDOM = document.querySelector('#data-copy'); //要复制文字的节点
var range = document.createRange();
// 选中需要复制的节点
range.selectNode(copyDOM);
// 执行选中元素
window.getSelection().addRange(range);
// 执行 copy 操作
var successful = document.execCommand('copy');
alert("复制成功")
return false;
}
var Url2=document.getElementById("tel_copy");
Url2.select(); // 选择对象
document.execCommand("Copy"); // 执行浏览器复制命令
alert("已复制好,可贴粘。");
}
$("#xinxioff").views(function() {
$("#layui-m-layer0").hide();
})
本文为Larwas原创文章,转载无需和我联系,但请注明来自larwas博客 https://larwas.com
最新评论