jquery-qrcode js生成二维码,完美解决 json

本文介绍了在前端使用jquery-qrcode.js库生成包含复杂JSON数据的二维码的解决方案。遇到中文乱码问题时,直接使用官网提供的最新版js文件即可解决,无需额外处理。官方提供多个示例,帮助开发者更好地理解和应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在项目中需要使用在前端通过js的方式生成一个二维码,二维码内容为后台传过来的json数据,数据中包含了中英文,引号等信息,直接使用github中的jquery-qrcode.js发现生成的二维码根本无法扫描出来,一看最后更新时间为4年前。最后遍寻解决方案无果,只好请教google。

解决方案很简单,使用官网的js就ok,中文乱码问题也无需转码,直接迎刃而解。
官网地址
https://larsjung.de/jquery-qrcode/



Options

The available options and their default values are:

{
    // render method: 'canvas', 'image' or 'div'
    render: 'canvas',
    // version range somewhere in 1 .. 40
    minVersion: 1,
    maxVersion: 40,

    // error correction level: 'L', 'M', 'Q' or 'H'
    ecLevel: 'L',

    // offset in pixel if drawn onto existing canvas
    left: 0,
    top: 0,

    // size in pixel
    size: 200,

    // code color or image element
    fill: '#000',

    // background color or image element, null for transparent background
    background: null,

    // content
    text: 'no text',

    // corner radius relative to module width: 0.0 .. 0.5
    radius: 0,

    // quiet zone in modules
    quiet: 0,

    // modes
    // 0: normal
    // 1: label strip
    // 2: label box
    // 3: image strip
    // 4: image box
    mode: 0,

    mSize: 0.1,
    mPosX: 0.5,
    mPosY: 0.5,

    label: 'no label',
    fontname: 'sans',
    fontcolor: '#000',

    image: null
}

Examples

Default values

Doesn’t make much sense, since it encodes the text: ‘no text’

$(selector).qrcode();

Customized

Some values changed

$(selector).qrcode({
    "size": 100,
    "color": "#3a3",
    "text": "http://larsjung.de/qrcode"
});

Same as above but rendered as div. The size of QR code might be slightly smaller than the desired size to make it pixel perfect. In this case it will be centered inside a container element with the desired sizes.

$(selector).qrcode({
    "render": "div",
    "size": 100,
    "color": "#3a3",
    "text": "http://larsjung.de/qrcode"
});

附官方demo

https://release.larsjung.de/jquery-qrcode/jquery-qrcode-0.12.0.zip

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值