宝玛科技网
您的当前位置:首页基于JavaScript实现生成名片、链接等二维码_javascript技巧

基于JavaScript实现生成名片、链接等二维码_javascript技巧

来源:宝玛科技网


废话不多说,直接贴代码了,具体内容如下;

 //生成的二维码放在此 div 中
//引入qrcode.js(到https://github.com/jeromeetienne/jquery-qrcode 下载 )

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; 
} 

以上内容就是本文的全部内容,希望大家喜欢。

显示全文