昨天接到一個任務,要求在對方已有的系統中通過修改前端js控件,将系統中原有的條形碼換成二維碼(

,是不是很糾結。)
google一下,發現有兩個開源的js庫,qrcode,qrcode-svg
位址:
qrcode.js:https://github.com/davidshimjs/qrcodejs
qrcode-svg.js:https://github.com/papnkukn/qrcode-svg
比較一下:
qrcode,生成的二維碼是一個png圖檔,非矢量
var qrcode = new QRCode(document.getElementById("qrcode"), {
width : 400,
height : 400,
correctLevel : QRCode.CorrectLevel.H
});
qrcode-svg,生成的是矢量二維碼,頁面 展示形式是SVG塊
var qrcode = new QRCode({
content: elText,
width: 256,
height: 256,
color: "#000000",
background: "#ffffff",
ecl: "L"
這兩種形式,如果隻是用于頁面展示,效果還可以接受。如果用于工業列印,那麼問題還是有的,問題在于列印的尺寸,品質等等。