楼上的说的很对,我现在才发现这个转换是不行的,在繁体系统里就会出问题了。我是用下面的脚本来做客户端的URLDecode转换的在简体下是可以,但在客户端为繁体的时候就不行了。真是气人。有没有好的解决办法?分数不够可以再加。 <script language=vbscript> Function URLDecode(enStr) dim deStr , c,i,v deStr="" for i=1 to len(enStr) c=Mid(enStr,i,1) if c="%" then v=eval("&h"+Mid(enStr,i+1,2)) if v<128 then deStr=deStr&chr(v) i=i+2 else if isvalidhex(mid(enstr,i,3)) then if isvalidhex(mid(enstr,i+3,3)) then v=eval("&h"+Mid(enStr,i+1,2)+Mid(enStr,i+4,2)) deStr=deStr&chr(v) i=i+5 else v=eval("&h"+Mid(enStr,i+1,2)+cstr(hex(asc(Mid(enStr,i+3,1))))) deStr=deStr&chr(v) i=i+3 end if Else destr=destr&c end if end if else if c="+" then deStr=deStr&" " else deStr=deStr&c end if end if next URLDecode=deStr End functionFunction isvalidhex(str) isvalidhex=true str=ucase(str) if len(str)<>3 then isvalidhex=false:exit function if left(str,1)<>"%" then isvalidhex=false:exit function c=mid(str,2,1) if not (((c>="0") and (c<="9")) or ((c>="A") and (c<="Z"))) then isvalidhex=false:exit function c=mid(str,3,1) if not (((c>="0") and (c<="9")) or ((c>="A") and (c<="Z"))) then isvalidhex=false:exit function End Function </script>
enStr.charCodeAt(4).toString(16)
v=eval("&h"+Mid(enStr,i+1,2)+Mid(enStr,i+4,2))Eval 函数
计算一个表达式的值并返回结果。在这里实际上就是:eval("&hD5E2")实际上就是把这个16进制字符串转换成为10进制数字!得到的结果是-10782//结果和数字编码有关!(不懂回头看无符号数字和有符号数字的知识)
关键是v=eval("&h"+Mid(enStr,i+1,2)+Mid(enStr,i+4,2))
这个的结果是-10782,JavaScript是怎么算出来的。
请帮我把这句翻译一下,马上结贴。
<!--
enStr = "%D5%E2"alert(parseInt(enStr.substr(1,2)+enStr.substr(4,2),16));
//-->
</SCRIPT>
Dim enStr
enStr = "%D5%E2"str = "&h"+Mid(enStr,2,2)+Mid(enStr,5,2)MsgBox CLNG(str)
</SCRIPT>
<!--
var enStr = "%D5%E2"
var i=0
var v=parseInt('0x'+enStr.substr(i+1,2)+enStr.substr(i+4,2))
if(v>0x8000)//如果首位是1,0x80000是首位是1的最小的2byte的int数字
{
v-=0x10000//按有符号数算,这里如果直接alert,javascript会自动转为long来计算
//你找一下帮助文件就知道了,javascript在需要的时候,会自动转换数据类型
alert(v)
//-->
</SCRIPT>
<script language=vbscript>
Function URLDecode(enStr)
dim deStr , c,i,v
deStr=""
for i=1 to len(enStr)
c=Mid(enStr,i,1)
if c="%" then
v=eval("&h"+Mid(enStr,i+1,2))
if v<128 then
deStr=deStr&chr(v)
i=i+2
else
if isvalidhex(mid(enstr,i,3)) then
if isvalidhex(mid(enstr,i+3,3)) then
v=eval("&h"+Mid(enStr,i+1,2)+Mid(enStr,i+4,2))
deStr=deStr&chr(v)
i=i+5
else
v=eval("&h"+Mid(enStr,i+1,2)+cstr(hex(asc(Mid(enStr,i+3,1)))))
deStr=deStr&chr(v)
i=i+3
end if
Else
destr=destr&c
end if
end if
else
if c="+" then
deStr=deStr&" "
else
deStr=deStr&c
end if
end if
next
URLDecode=deStr
End functionFunction isvalidhex(str)
isvalidhex=true
str=ucase(str)
if len(str)<>3 then isvalidhex=false:exit function
if left(str,1)<>"%" then isvalidhex=false:exit function
c=mid(str,2,1)
if not (((c>="0") and (c<="9")) or ((c>="A") and (c<="Z"))) then isvalidhex=false:exit function
c=mid(str,3,1)
if not (((c>="0") and (c<="9")) or ((c>="A") and (c<="Z"))) then isvalidhex=false:exit function
End Function
</script>
赫赫!为什么不百度一下呢?