function str2utf8(str)
{
// UCS-2和UTF8都是unicode的一種編碼方式
// js代碼中使用的是UCS-2編碼
var code;
var utf = "";
for (var i = 0; i < str.length; i++)
{
code = str.charCodeAt(i);//回傳每個字符的Unicode 編碼
if (code < 0x0080) {
utf += str.charAt(i);//回傳指定位置的字符
}
else if (code < 0x0800) {
utf += String.fromCharCode(0xC0 | ((code >> 6) & 0x1F));
utf += String.fromCharCode(0x80 | ((code >> 0) & 0x3F));
}
else if (code < 0x10000) {
utf += String.fromCharCode(0xE0 | ((code >> 12) & 0x0F));
utf += String.fromCharCode(0x80 | ((code >> 6) & 0x3F));
utf += String.fromCharCode(0x80 | ((code >> 0) & 0x3F));
}
else
{
throw "不是UCS-2字符集"
}
}
return utf;
}
uj5u.com熱心網友回復:
return 那塊可以啊uj5u.com熱心網友回復:
大佬,能發下代碼嗎,謝謝uj5u.com熱心網友回復:
大佬能發下怎么添加的,我現在能決議字母數字的
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/135360.html
標籤:HTML(CSS)
上一篇:用戶在輸入頁面上輸入文字,需要保存到另外一個頁面,且下次打開還存在
下一篇:django前端ajax問題
