zoukankan      html  css  js  c++  java
  • 刷新页面微信二维码图片随机换,点击按钮自动复制对应微信号

    <div style="text-align: center;">
    <p style="font-size: 18px;color: rgb(255, 79, 121);">添加微信号</p>
    <span style="font-size: 18px;margin-left: 10%;" id="cod">jyl88jimei</span><br />
    <img src="images/jyl88jimei.jpg" id="img" style=" 80%;" alt="jyl88jimei" />
    </div>

    <p id="copy" style="background-image:none;">
    <img src="images/TiaoDong.png">
    </p>

    var oImg = document.getElementById("img");
    var arr = ["jyl88jimei", "zy88fx", "Lab88fx"];//图片名称
    window.onload = function() {
    oImg.src ="images/"+ arr[Math.floor(Math.random() * arr.length)] + '.jpg';//图片路径
    //先得到图片
    var img=document.getElementById("img");
    //得到图片路径
    var path=oImg.src;
    //从路径中截取图片名[包括后缀名]
    var filename;
    if(path.indexOf("/")>0)//如果包含有"/"号 从最后一个"/"号+1的位置开始截取字符串
    {
    filename=path.substring(path.lastIndexOf("/")+1,path.length);
    }
    else
    {
    filename=path;
    }

    var tx=filename.substring(0, filename.indexOf('.'));//获取“.”前面的字符串
    $("#cod").html(tx);
    $(".wxName").html(tx);
    function copyArticle(event) {
    const range = document.createRange();
    range.selectNode(document.getElementById('cod'));
    const selection = window.getSelection();
    if(selection.rangeCount > 0) selection.removeAllRanges();
    selection.addRange(range);
    document.execCommand('copy');
    alert("复制微信号成功,请前往微信添加好友!")
    }
    document.getElementById('copy').addEventListener('click', copyArticle, false);

    };

  • 相关阅读:
    (23)odoo中的domain表达式
    (11)lambda表达式用法
    (22)odoo 安装旧模块报错处理
    (21)odoo中的QWeb模板引擎
    (10)列表操作
    (09)异常处理
    (08)文件与目录
    (07)内存使用和变量赋值
    (06)正则表达式
    vue router路由(三)
  • 原文地址:https://www.cnblogs.com/zyl-930826/p/8655536.html
Copyright © 2011-2022 走看看