JS生成名片二维码插件,用于destoon6.0 编码不限制 - destoon网站专家(destoon.cc) 出品
1、调用已经做好,请自己对应添加到你的模板中即可,记得引入主要的JS,包里有文件
展示效果图:
方法如下:
<div id = "qrcodeid"></div> //生成的二维码放在此 div 中
<script type="text/javascript" src=https://destoon.cc/skin/taomodi/image/nopic.gif>cript>//引入qrcode.js(到https://github.com/jeromeetienne/jquery-qrcode 下载 )
<script>
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;
}
</script>
<script>//此处生成名片二维码(如要生成普通链接二维码 则 "text"参数值 直接替换成普通链接即可)
var the_text = "BEGIN:VCARD \r\nFN:{$item[truename]} \r\nTEL;CELL,VOICE:{$item[mobile]} \r\nTITLE:{$item[career]}\r\nORG:{$item[company]} \r\nEMAIL;INTERNET,HOME:{$item[mail]} \r\nADR;WORK,POSTAL:{$item[address]} \r\nURL:{userurl($username)} \r\nEND:VCARD";
the_text = utf16to8(the_text);
//alert(the_text);
jQuery('#qrcodeid').qrcode({
width:120,
height:120,
render:"canvas", //设置渲染方式 table canvas
typeNumber : -1, //计算模式
correctLevel : 0,//纠错等级
background : "#ffffff",//背景颜色
foreground : "#000000",//前景颜色
text:the_text
});
</script>