帮忙从 vbscript 翻译为 javascript
<script language="vbscript">
Function URLEncode(str)
Dim s,c,a,t
For i=1 To Len(str)
c = Mid(str,i,1)
a = ASC(c)
If a<0 OR a>255 Then
t=Hex(a)
While len(t) mod 2 > 0
t = "0" & t
Wend
For j=1 To len(t)-1 Step 2
s = s & "%" & Mid(t,j,2)
Next
ElseIf a=32 Then
s = s & "+"
ElseIf (a>=48 and a<=57) or (a>=65 and a<=90) or (a>=97 and a<=122) Then
s = s & c
ElseIf a>0 and a<16 Then
s = s & "%0" & Hex(a)
ElseIf a>=16 and a<256 Then
s = s & "%" & Hex(a)
Else
s = s & c
End If
Next
URLEncode = s
End Function
Function URLDecode(input)
Dim str,code,a(3),b(1)
str=""
code=input
code=Replace(code,"+"," ")
Const hexstr = "0123456789ABCDEF"
While len(code)>0
If InStr(code,"%")>0 Then
str = str & Mid(code,1,InStr(code,"%")-1)
code = Mid(code,InStr(code,"%"))
a(0) = UCase(Mid(code,2,1))
a(1) = UCase(Mid(code,3,1))
If a(1)<>"" And InStr(hexstr,a(0))>0 And InStr(hexstr,a(1))>0 Then
b(0) = Eval("&H" & a(0) & a(1))
If b(0)>127 And Mid(code,4,1)="%" And len(code)>=6 Then
a(2) = UCase(Mid(code,5,1))
a(3) = UCase(Mid(code,6,1))
If a(3)<>"" And InStr(hexstr,a(2))>0 And InStr(hexstr,a(3))>0 Then
b(1) = Eval("&H" & a(2) & a(3))
str = str & chr(b(0)*256+b(1))
code = Mid(code,7)
Else
str = str & "%"
code = Mid(code,2)
End If
Else
str = str & chr(b(0))
code = Mid(code,4)
End If
Else
str = str & "%"
code = Mid(code,2)
End If
Else
str = str & code
code = ""
End If
Wend
URLDecode = str
End Function
</script>
<script language="javascript">
function encodeURIComponent(code){
return URLEncode(code);
}
function decodeURIComponent(code){
return URLDecode(code);
}
function encodeURI(code){
return URLEncode(code);
}
function decodeURI(code){
return URLDecode(code);
}
</script>
Function URLEncode(str)
Dim s,c,a,t
For i=1 To Len(str)
c = Mid(str,i,1)
a = ASC(c)
If a<0 OR a>255 Then
t=Hex(a)
While len(t) mod 2 > 0
t = "0" & t
Wend
For j=1 To len(t)-1 Step 2
s = s & "%" & Mid(t,j,2)
Next
ElseIf a=32 Then
s = s & "+"
ElseIf (a>=48 and a<=57) or (a>=65 and a<=90) or (a>=97 and a<=122) Then
s = s & c
ElseIf a>0 and a<16 Then
s = s & "%0" & Hex(a)
ElseIf a>=16 and a<256 Then
s = s & "%" & Hex(a)
Else
s = s & c
End If
Next
URLEncode = s
End Function
Function URLDecode(input)
Dim str,code,a(3),b(1)
str=""
code=input
code=Replace(code,"+"," ")
Const hexstr = "0123456789ABCDEF"
While len(code)>0
If InStr(code,"%")>0 Then
str = str & Mid(code,1,InStr(code,"%")-1)
code = Mid(code,InStr(code,"%"))
a(0) = UCase(Mid(code,2,1))
a(1) = UCase(Mid(code,3,1))
If a(1)<>"" And InStr(hexstr,a(0))>0 And InStr(hexstr,a(1))>0 Then
b(0) = Eval("&H" & a(0) & a(1))
If b(0)>127 And Mid(code,4,1)="%" And len(code)>=6 Then
a(2) = UCase(Mid(code,5,1))
a(3) = UCase(Mid(code,6,1))
If a(3)<>"" And InStr(hexstr,a(2))>0 And InStr(hexstr,a(3))>0 Then
b(1) = Eval("&H" & a(2) & a(3))
str = str & chr(b(0)*256+b(1))
code = Mid(code,7)
Else
str = str & "%"
code = Mid(code,2)
End If
Else
str = str & chr(b(0))
code = Mid(code,4)
End If
Else
str = str & "%"
code = Mid(code,2)
End If
Else
str = str & code
code = ""
End If
Wend
URLDecode = str
End Function
</script>
<script language="javascript">
function encodeURIComponent(code){
return URLEncode(code);
}
function decodeURIComponent(code){
return URLDecode(code);
}
function encodeURI(code){
return URLEncode(code);
}
function decodeURI(code){
return URLDecode(code);
}
</script>
...全文
相关推荐
ASP网站实例开发源码——双语版本的中国翻译人才库源码.zip
ASP网站实例开发源码——双语版本的中国翻译人才库源码.zip
什么是脚本,javascript?
动态程序一般有两种实现方式,一是二进制方式,一是脚本方式。 二进制方式是先将我们编写的程序进行编译,变成机器可识别的指令代码(如.exe文件),然后再执行。这种编译好的程序我们只能执行、使用,却看不到他的程序内容。脚本简单地说就是一条条的文字命令,这些文字命令是我们可以看到的(如可以用记事本打开查看、编辑),脚本程序在执行时,是由系统的一个解释器,将其一条条的翻译成机器可识别的指令,并按程序顺序执行。因为脚本在执行时多了一道翻译的过程,所以它比二进制程序执行效率要稍低一些。ASP、PHP、CGI、JSP等,都是脚本语言。
ASP源码ASP企业网站设计与实现(源代码+论文+开题报告+外文翻译)
ASP源码ASP企业网站设计与实现(源代码+论文+开题报告+外文翻译)本资源系百度网盘分享地址
日文版多标签webbrowser
日文版多标签浏览器,支持关闭标签,保存图像等。支持选中文字右键选择搜索引擎进行搜索或才翻译
ASP企业网站设计与实现(源代码+论文+开题报告+外文翻译).zip
ASP企业网站设计与实现(源代码+论文+开题报告+外文翻译).zip


