課程
/后端開發
/Java
/Java生成二維碼
如何處理亂碼問題
2018-08-06
源自:Java生成二維碼 6-1
正在回答
//解決中文亂碼
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));
? ? ? ? }
? ? }
? ? return out;
}
var str = toUtf8("http://www.xianlaiwan.cn");?
?$("#qrcode").qrcode(str);?
可以使用,我用了
舉報
二維碼無處不在,自己動手用Java生成二維碼,三種生成方式任你選
1 回答亂碼問題怎么解決
1 回答qrcode方式創建二維碼中文亂碼問題
2 回答中文的亂碼
5 回答VCard中文亂碼
2 回答中文亂碼了
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2018-08-27
//解決中文亂碼
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;
}
var str = toUtf8("http://www.xianlaiwan.cn");?
?$("#qrcode").qrcode(str);?
可以使用,我用了