js实现点击按钮复制div指定内容到剪切板粘贴板
未知
2023-06-29 17:50:02
0
问题描述:
  
   做一个底部点击【添加微信】,出现一个弹窗,出现弹窗的同时复制指定的值到粘贴板上。

tulan

解决办法:

    <div id="copykey" style="display: none">tuln1406a</div>

    <div class="changan" id="toolbar">

        <div class="firdiv"> 添加微信好友了解产品 </div>

        <div class="secdive"><a onclick="dkcf()" title="微信"><span>添加微信</span></a></div>

    </div>  

    <div id="wxnr" >

        <div class="nrdf">

            <i onclick="gbcf()">X</i>
            <img src="333.png" alt=""/>
            <p class="fuzhi">复制成功</p>
            <p class="wei" id="input">微信号:tulan1406</p>
            <p class="wei">添加微信好友,详细了解产品</p>
            <p class="zhi" onclick="gbcf()"><span class="wx">知道了</span></p>

        </div>
    </div>

<style>

    #toolbar { display:block; position: fixed; bottom: 0; width: 100%; z-index: 888; height: 57px; left: 0; background: black}
    #toolbar .firdiv { float: left; width: 60%; color:black;line-height: 60px;font-size: 15px;background: white;}
    #toolbar .secdive{float: right;width: 40%;background: #1AAD17;line-height: 60px}
    #toolbar span{font-weight: 800;font-size: 16px;color: #fff;}
    .changan{   width:100%; max-width:750px;   height:5.125rem;  line-height:5.125rem;  text-align:center;  color:#fff; font-size:22px; position:fixed; bottom:0;   box-shadow:0px 0px 10px rgba(0,0,0,0.4);}

    #wxnr { width: 100%; height: 100%; max-width: 640px; min-width: 320px; position: fixed; top: 0; z-index: 1000; display: none; background: rgba(0,0,0,.6); }

    #wxnr .nrdf { margin: auto; position: absolute; top: 30%; left: 0; right: 0; width: 80%; height: 37%; padding: 12px; padding-top: 26px; margin-top: -12px; text-align: center; background-color: #FFFFFF; box-shadow: 0px 2px 6px #777; -webkit-box-shadow: 0px 2px 6px #777; -moz-box-shadow: 0px 2px 6px #777; border-radius: 10px; }

    #wxnr img { width: 55px; height: 55px; display: block; margin: 0 auto; }

    #wxnr .fuzhi { font-size: 20px; line-height: 15px; text-align: center; margin-top: 10px;font-weight: 800}

    #wxnr .wei { font-size: 15px; line-height: 15px; text-align: center; margin-top: 10px;color: #676767}
    #wxnr i { position: absolute;top: 8px;right: 13px;width: 15px;height: 15px;font-size: 0.px;line-height: 16px;text-align: center;color: gray;font-weight: bold;font-style: normal;cursor: pointer; }
    #wxnr .zhi {padding: 0 25%;}
    #wxnr p .wx { padding:13px 0;background: #1AAD17;border-radius: 23px;display: block; width: 100%;color: white;}

</style>

<script>

  /* 打开微信弹窗 并复制指定值*/

function dkcf(){

  $('#wxnr').fadeIn("fast");

    const div = document.getElementById("copykey");

    const input = document.createElement("input");

    document.body.appendChild(input);

    input.value = div.innerText;

    input.select();

    try {

        if (document.execCommand("copy", false)) {

          layer.msg("div 内容复制成功");

        } else {
          layer.msg("div 内容复制失败");

        }
    } catch (error) {
        console.log(error, "error");

      } finally {
        input.remove();

    }
}

/* 关闭微信弹窗 */

function gbcf(){

  $('#wxnr').fadeOut("fast");

}
</script>


相关内容

PHP sg15 实战教程...
PHP SG15实战教程:从基础到高级,学习PHP语言安全协议与技...
2026-02-11 01:23:35
PHP与YAML集成:实现...
本文介绍了PHP与YAML集成的实现方式,包括读取和写入YAML文...
2026-02-03 01:23:45
"从基础到实践:关于PHP...
本文详细介绍了PHP `min_spare_servers` 参数...
2025-12-28 01:23:46
"从入门到精通:MySQL...
本文全面解析了MySQL视图概念、操作及技巧。介绍其定义、创建、查...
2025-11-28 01:23:45
淘宝优惠券如何快速找到?教...
摘要: 本文介绍了如何快速找到淘宝优惠券的方法,包括关注官方活动...
2025-11-14 01:23:41
Tomcat在云服务器中的...
摘要: 本文探讨了Tomcat在云服务器中实现高可用性的方法,包...
2025-11-03 01:23:42

热门资讯

downloadable fo... downloadable font: Glyph bbox was incorrect怎么处理
腾讯邮箱qq邮箱使用SMTP开... 第一步:登录 https://mail.qq.com/ 登录后点击设置---账号 第二步:点击【开启...
layui tooltip提示... 在layui表单中,我们想把一个标签做出提示,以标明这个表单元素是做什么有什么功能时,就可以用上提...
layui中出错Unexpec... layui中出错Unexpected identifier
解决Phpcms V9手机门户... 第一步:开启手机网站。位置:模块 》手机门户 》 添加手机站点,如果模块里面没有手机门户,那么就在模...
JavaScript获取当前协... JavaScript获取当前协议,域名,路径
JS实现html打印功能,打印... !DOCTYPE htmlhtmlhead meta charset=utf-8 title打印功能...
bootstrap 图片文字居... 问题描述: 让图片和文字居中显示。 解决办法: !-- style--.navbars img{ m...
bootstrap图片排版布局 问题描述: 在使用bootstrap的时候,出现了这样的问题。 排版对不齐。 解决办法: 通过上图发...