Home > php教程 > php手册 > 使用jquery.qrcode生成二维码

使用jquery.qrcode生成二维码

WBOY
Release: 2016-06-07 11:43:08
Original
1266 people have browsed it

使用jquery.qrcode生成二维码
原文地址http://www.bieanju.com/75.html
试验的时候发现不能识别中文内容的二维码,通过查找多方资料了解到,jquery-qrcode是采用charCodeAt()方式进行编码转换的。而这个方法默认会获取它的Unicode编码,如果有中文内容,在生成二维码前就要把字符串转换成UTF-8,然后再生成二维码。您可以通过以下函数来转换中文字符串:
function toUtf8(str) {    <br>     var out, i, len, c;    <br>     out = "";    <br>     len = str.length;    <br>     for(i = 0; i          c = str.charCodeAt(i);    <br>         if ((c >= 0x0001) && (c              out += str.charAt(i);    <br>         } else if (c > 0x07FF) {    <br>             out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));    <br>             out += String.fromCharCode(0x80 | ((c >>  6) & 0x3F));    <br>             out += String.fromCharCode(0x80 | ((c >>  0) & 0x3F));    <br>         } else {    <br>             out += String.fromCharCode(0xC0 | ((c >>  6) & 0x1F));    <br>             out += String.fromCharCode(0x80 | ((c >>  0) & 0x3F));    <br>         }    <br>     }    <br>     return out;    <br> } 以下示例:
var str = toUtf8("程序猿!"); <br> $('#code').qrcode(str); 

附件 qrcode.zip ( 5.88 KB 下载:248 次 )

AD:真正免费,域名+虚机+企业邮箱=0元

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template