JS生成链接二维码

需要引入两个js文件:
1)jquery.min.js
2)jquery.qrcode.min.js

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>生成名片二维码</title>
</head>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.qrcode.min.js"></script>
<style type="text/css" >
body {
    position: absolute; top: 0%;
     left: 0%; width:100%; 
     height:100%; 
     background-color: #a7aaad; 
     -moz-opacity: 0.7; 
     opacity:0.5;
     z-index:1001; 
     filter: alpha(opacity=40);
}
.back{
    background-image: url("image/img1.jpg");
    z-index:100;
}
</style>
<script type="text/javascript">
$(function(){
    //此处生成名片二维码
     var the_text = utf16to8("https://www.zhihu.com/question/40117062");
    //alert(the_text);
    $('#qrcodeid').qrcode({
        width:140,
        height:140,
        render:"canvas", //设置渲染方式 table canvas
        typeNumber : -1,  //计算模式 
        correctLevel  : 0,//纠错等级 
        background   : "#ffffff",//背景颜色 
        foreground   : "#000000",//前景颜色 
        text:the_text
    }); 
});
function utf16to8(str) { //解决中文乱码
  var out, i, len, c; 
  out = ""; 
  len = str.length; 
  for(i = 0; i < len; i++) { 
      c = str.charCodeAt(i); 
      if ((c >= 0x0001) && (c <= 0x007F)) { 
        out += str.charAt(i); 
      } else if (c > 0x07FF) { 
        out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F)); 
        out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F)); 
        out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F)); 
      } else { 
        out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F)); 
        out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F)); 
      } 
  } 
  return out; 
} 
</script>
<body >
    <div class="back"></div>
    <div id = "qrcodeid"></div>  <!-- 生成的二维码放在此div中 -->
</body>
</html>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值