<!
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=gb2312 " />
< title > 无标题文档 </ title >
< script type = " text/javascript " >
function doCode(deCode) {
var txt1 = document.getElementById("txt1");
var txt2 = document.getElementById("txt2");
if(deCode){
txt2.value = urlDecode(txt1.value);
}else{
txt2.value = urlEncode(txt1.value);
}
}
function urlDecode(str)
{
if("undefined" == typeof decodeURIComponent)
{
return unescape(str).replace(//+/g, ' ').replace(/%2B/g,'+');
} else {
/**//*just use my self decode script*/
/**//*return decodeURIComponent(str.replace(//+/g, ' ').replace(/%2B/g,'+'));*/
return unescape(str).replace(//+/g, ' ').replace(/%2B/g,'+');
}
}
function urlEncode(str)
{
var i,c,ret="",strSpecial="!/"#$%&'()*+,/:;<=>?@[/]^`{|}~%";
for(i=0;i<str.length;i++)
{
c=str.charAt(i);
if(c==" ")
ret+="+";
else if(strSpecial.indexOf(c)!=-1)
ret+="%"+str.charCodeAt(i).toString(16);
else
ret+=c;
}
return ret;
};
</script>
</head>
<body>
<div id="output">
Source:<br />
<textarea name="txt1" cols="52" rows="12"></textarea><br />
Destination:<br />
<textarea name="txt2" cols="52" rows="12"></textarea><br />
<input name="Decode" type="button" value="Decode" οnclick="doCode(true);" />
<input name="Encode" type="button" value="Encode" οnclick="doCode(false);" />
</div>
</body>
</html>
< html xmlns = " http://www.w3.org/1999/xhtml " >
< head >
< meta http - equiv = " Content-Type " content = " text/html; charset=gb2312 " />
< title > 无标题文档 </ title >
< script type = " text/javascript " >
function doCode(deCode) {
var txt1 = document.getElementById("txt1");
var txt2 = document.getElementById("txt2");
if(deCode){
txt2.value = urlDecode(txt1.value);
}else{
txt2.value = urlEncode(txt1.value);
}
}
function urlDecode(str)
{
if("undefined" == typeof decodeURIComponent)
{
return unescape(str).replace(//+/g, ' ').replace(/%2B/g,'+');
} else {
/**//*just use my self decode script*/
/**//*return decodeURIComponent(str.replace(//+/g, ' ').replace(/%2B/g,'+'));*/
return unescape(str).replace(//+/g, ' ').replace(/%2B/g,'+');
}
}
function urlEncode(str)
{
var i,c,ret="",strSpecial="!/"#$%&'()*+,/:;<=>?@[/]^`{|}~%";
for(i=0;i<str.length;i++)
{
c=str.charAt(i);
if(c==" ")
ret+="+";
else if(strSpecial.indexOf(c)!=-1)
ret+="%"+str.charCodeAt(i).toString(16);
else
ret+=c;
}
return ret;
};
</script>
</head>
<body>
<div id="output">
Source:<br />
<textarea name="txt1" cols="52" rows="12"></textarea><br />
Destination:<br />
<textarea name="txt2" cols="52" rows="12"></textarea><br />
<input name="Decode" type="button" value="Decode" οnclick="doCode(true);" />
<input name="Encode" type="button" value="Encode" οnclick="doCode(false);" />
</div>
</body>
</html>