首页 > 语言 > JavaScript > 正文

利用jquery.qrcode在页面上生成二维码且支持中文

2024-05-06 14:29:49
字体:
来源:转载
供稿:网友
实例如下:
代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>使用jquery-qrcode生成二维码,支持中文</title>
    <script src="../Scripts/jquery-1.4.4.min.js" type="text/javascript"></script>
    <script src="jquery.qrcode.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        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;
        }
        $(function () {
            jQuery('#output').qrcode(utf16to8("今天天气不错"));
        })   
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选