Rumah > Artikel > hujung hadapan web > Menjana kad perniagaan, pautan dan kod QR lain berdasarkan kemahiran JavaScript_javascript
Tanpa berlengah lagi, mari siarkan kod kandungan khusus adalah seperti berikut;
<div id = "qrcodeid"></div> //生成的二维码放在此 div 中 <script type="text/javascript" src="js/jquery.qrcode.min.js"></script>//引入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:姓名 \r\nTEL;CELL,VOICE:15000000000 \r\nTITLE:职称 \r\nORG:公司(组织) \r\nEMAIL;INTERNET,HOME:123@qq.com \r\nADR;WORK,POSTAL:地球中国山东... \r\nURL:http://leerd.cn \r\nEND:VCARD"; the_text = utf16to8(the_text); //alert(the_text); jQuery('#qrcodeid').qrcode({ width:140, height:140, render:"canvas", //设置渲染方式 table canvas typeNumber : -1, //计算模式 correctLevel : 0,//纠错等级 background : "#ffffff",//背景颜色 foreground : "#000000",//前景颜色 text:the_text }); </script>