js编码问题如何将%b1%b1%be%a9转化为北京 <script type="text/javascript">str = "%b1%b1%be%a9";alert(str); //如何显示北京</script> 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 escape encodeURI encodeURIComponent unescape decodeURI 这几个都试过了,都不好使,请问如何转换? 昨天有人问中国,今天是北京!本地用时记得下载http://www.btbtd.org/test/sqJsTools/tools/Url/Url/CP936.jsL@_@K<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>shawl.qiu template</title></head><body><script type="text/javascript" src="http://www.btbtd.org/test/sqJsTools/tools/Url/Url/CP936.js"></script><script type="text/javascript">/*<![CDATA[*/ var pe = "%b1%b1%be%a9"; document.write("pe: "+pe); document.write("<br />de: "+IDecodeURIGb(pe, [CP936])); document.write("<hr />"); function IDecodeURIGb(Source, CP936) // Pe = percent encoding; %xx[,%xx] { // shawl.qiu code, return string|void return; Func: fGetUtfHex var bStr = false; if(Source.constructor==String) Source = [Source], bStr = true; //if(CP936==null) fFatalError("编码映射表不能为空!"); var iLBound = iUBound = 0; iLBound = -1; iUBound = 0x7f; Source[0] = Source[0].replace(/\+/g, " "); var Len = Source[0].length; for(var i=0; i<Len; i++) { var iIndex = Source[0].indexOf("%", i); if(iIndex===-1) break; var sHex = Source[0].slice(iIndex+1, iIndex+3); var iCode = parseInt(sHex, 16); //document.write("<br/>sHex: "+sHex); if(iCode>-1&&iCode<=0x7f) // ascii { Source[0] = [ Source[0].slice(0, iIndex) , String.fromCharCode(iCode) , Source[0].slice(iIndex+3) ].join(""); } else { var sHexRaw = Source[0].slice(iIndex+3, iIndex+6); //document.write("<br/>sHexRaw: "+sHexRaw); if(sHexRaw.charAt(0)!="%") continue; sHex += sHexRaw.slice(1); var sUniHex = fGetUtfHex(sHex, CP936); //document.write("<br/>sHex: "+sHex); //document.write("<br/>sUniHex: "+sUniHex); Source[0] = [ Source[0].slice(0, iIndex) , String.fromCharCode(parseInt(sUniHex, 16)) , Source[0].slice(iIndex+6) ].join(""); } // end if(iCode<-1&&iCode<0x7f) } // end for(var i=0; i<Len; i++) if(bStr) return Source[0]; } // end function IDecodeURIGb(Source) function fGetUtfHex(sGbHex, CP936) { // shawl.qiu code, return string sGbHex = sGbHex.toUpperCase(); var iIndex = CP936[0].indexOf(sGbHex); if(iIndex===-1) return "0x005F"; var iBegin = iIndex+sGbHex.length+1; return CP936[0].substring(iBegin, iBegin+6); } // end function fGetMapTableChar(sHex)</script></body></html> 这是 GBK 编码,js 默认解码用 uft-8 编码!昨天类似贴:http://topic.csdn.net/u/20100816/14/9bf7ac8c-6a44-4a7d-950d-83743b336594.html 谢谢,太棒了。请问IDecodeURIGb(pe, [CP936]))第二个参数是什么意思? []代表什么啊? 从来没有见过。 CP936 是 CP936.js 中声明的变量,[]是数组的简易格式,即将参数用数组封装起来,虽然这段代码可以运行,但是很多地方可以优化! 请教高手正则的反义 有谁用过jQuery.Boxy 100分!javascript文盲请大家解决个问题 关于exobud播放器的进度条问题!请大家帮忙看看! 求教大家帮我修改我这个错误(应该很简单,因为我不懂js) 如何实现 图片导航器的功能?就像 photoshop里的那个导航一样 第一次得奖,撒点分 有关于image对像问题 急:检索并修改URL中的变量 js 全局变量问题 正则表达式的问题 js问题,请问怎样能够得到滚动条的滑块的长度
这几个都试过了,都不好使,请问如何转换?
http://www.btbtd.org/test/sqJsTools/tools/Url/Url/CP936.jsL@_@K
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>shawl.qiu template</title>
</head>
<body><script type="text/javascript" src="http://www.btbtd.org/test/sqJsTools/tools/Url/Url/CP936.js"></script>
<script type="text/javascript">
/*<![CDATA[*/ var pe = "%b1%b1%be%a9";
document.write("pe: "+pe);
document.write("<br />de: "+IDecodeURIGb(pe, [CP936]));
document.write("<hr />"); function IDecodeURIGb(Source, CP936) // Pe = percent encoding; %xx[,%xx]
{ // shawl.qiu code, return string|void return; Func: fGetUtfHex
var bStr = false;
if(Source.constructor==String) Source = [Source], bStr = true; //if(CP936==null) fFatalError("编码映射表不能为空!"); var iLBound = iUBound = 0;
iLBound = -1; iUBound = 0x7f; Source[0] = Source[0].replace(/\+/g, " "); var Len = Source[0].length; for(var i=0; i<Len; i++)
{
var iIndex = Source[0].indexOf("%", i);
if(iIndex===-1) break; var sHex = Source[0].slice(iIndex+1, iIndex+3);
var iCode = parseInt(sHex, 16); //document.write("<br/>sHex: "+sHex); if(iCode>-1&&iCode<=0x7f) // ascii
{
Source[0] =
[
Source[0].slice(0, iIndex)
, String.fromCharCode(iCode)
, Source[0].slice(iIndex+3)
].join("");
}
else
{
var sHexRaw = Source[0].slice(iIndex+3, iIndex+6);
//document.write("<br/>sHexRaw: "+sHexRaw);
if(sHexRaw.charAt(0)!="%") continue;
sHex += sHexRaw.slice(1);
var sUniHex = fGetUtfHex(sHex, CP936);
//document.write("<br/>sHex: "+sHex);
//document.write("<br/>sUniHex: "+sUniHex);
Source[0] =
[
Source[0].slice(0, iIndex)
, String.fromCharCode(parseInt(sUniHex, 16))
, Source[0].slice(iIndex+6)
].join("");
} // end if(iCode<-1&&iCode<0x7f)
} // end for(var i=0; i<Len; i++) if(bStr) return Source[0];
} // end function IDecodeURIGb(Source) function fGetUtfHex(sGbHex, CP936)
{ // shawl.qiu code, return string
sGbHex = sGbHex.toUpperCase();
var iIndex = CP936[0].indexOf(sGbHex);
if(iIndex===-1) return "0x005F"; var iBegin = iIndex+sGbHex.length+1;
return CP936[0].substring(iBegin, iBegin+6);
} // end function fGetMapTableChar(sHex)</script>
</body>
</html>
http://topic.csdn.net/u/20100816/14/9bf7ac8c-6a44-4a7d-950d-83743b336594.html
请问IDecodeURIGb(pe, [CP936]))第二个参数是什么意思? []代表什么啊? 从来没有见过。
虽然这段代码可以运行,但是很多地方可以优化!