zoukankan      html  css  js  c++  java
  • 二维码生成(QRCode.js)

    什么是 QRCode.js?

    QRCode.js 是一个用于生成二维码的 JavaScript 库。主要是通过获取 DOM 的标签,再通过 HTML5 Canvas 绘制而成,不依赖任何库。


    基本用法

    <div id="qrcode"></div>
    <script type="text/javascript">
    new QRCode(document.getElementById("qrcode"), "http://www.runoob.com");  // 设置要生成二维码的链接
    </script>

    或者使用一些可选参数设置:

    var qrcode = new QRCode("test", {
        text: "http://www.runoob.com",
        width: 128,
        height: 128,
        colorDark : "#000000",
        colorLight : "#ffffff",
        correctLevel : QRCode.CorrectLevel.H
    });

    同样我们可以使用以下方法:

    qrcode.clear(); // 清除代码
    qrcode.makeCode("http://www.w3cschool.cc"); // 生成另外一个二维码

    浏览器支持

    支持该库的浏览器有:IE6~10, Chrome, Firefox, Safari, Opera, Mobile Safari, Android, Windows Mobile, 等。


    示例:

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
        <meta content="yes" name="apple-mobile-web-app-capable">
        <meta content="yes" name="apple-touch-fullscreen">
        <meta content="telephone=no,email=no" name="format-detection">
        <meta name="App-Config" content="fullscreen=yes,useHistoryState=yes,transition=yes">
        <title>二维码</title>
    </head>
    <body>
        <div class="wrapper">
            <textarea id="txtContent" cols="50" rows="5"></textarea>
            <button type="button" onclick="getCode();">生成</button>
            <div id="qrCode"></div>
            <script type="text/javascript" src="http://cdn.bootcss.com/jquery/2.1.1/jquery.min.js"></script>
            <script type="text/javascript" src="http://static.runoob.com/assets/qrcode/qrcode.min.js"></script>
            <script type="text/javascript">
             var qrCode = document.getElementById("qrCode");
             var txtContent = document.getElementById("txtContent");
             var qrcode=new QRCode(qrCode,{
                300,
                height:300,
                correctLevel:QRCode.CorrectLevel.L
            });
    
             function getCode() {
                qrcode.makeCode(txtContent.value);
            }  
        </script>
    </body>
    </html>

    结果:

  • 相关阅读:
    oracle 之 while循环月份
    oracle 之 for循环表
    基本类型与字符串之间的转换
    java的数据类型和mysql的数据类型和Oracle数据类型
    EasyPoi导入数据后,导出发生错误的数据报[object Object]
    mysql查询表名是否存在和oracle查询表名是否存在
    mysql服务相关命令
    vue:按钮后面加一个下拉箭头
    js删除对象中的属性使用delete
    为什么在前端存入的日期,到后台却多了8个小时?而且前端显示的又是很丑的时间戳
  • 原文地址:https://www.cnblogs.com/chen-cheng/p/9223551.html
Copyright © 2011-2022 走看看