JQuery生成二维码

<!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>Test生成二维码,支持中文</title>  
   
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.1.min.js"></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(
"速冻滑子菇,承德森源绿色食品有限公司,网址:http://xxxxxxx/SitePages/ProductViewNew.aspx?PID=7a988c8f-c148-4a90-a6a8-e713b82a183f"));  
        })      
    
</script>  
</head>  
<body>  
<div id="output"></div>  
</body>  
</html>

/Files/jakin/JS文件.rar

注意:此方法仅支持IE9及以上版本。

posted @ 2014-11-26 15:45  Jakin.zhou  阅读(140)  评论(0编辑  收藏  举报