js使用qrcode插件生成二维码

来源:互联网 发布:防sql注入方法 编辑:程序博客网 时间:2024/04/25 20:00
<script src="js/jquery.min.js"></script>

<script type="text/javascript" src="js/jquery.qrcode.min.js"></script>


 <div id="code"></div>


<script>
$(function() {
        makeQr("今晚撸",100,100);
});
function toUtf8(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 makeQr(str,width,height){//二维码的内容,宽,高
        $("#code").qrcode({
            width: width,
            height:height,  
            text:toUtf8(str)
        });
}

</script>

0 0