URL编码反编码

ContractedBlock.gif ExpandedBlockStart.gif
None.gif<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
None.gif
<html xmlns="http://www.w3.org/1999/xhtml">
None.gif
<head>
None.gif
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
None.gif
<title>无标题文档</title>
None.gif
<script type="text/javascript">
ExpandedBlockStart.gifContractedBlock.gif
function doCode(deCode)dot.gif{
InBlock.gif
var txt1 = document.getElementById("txt1");
InBlock.gif
var txt2 = document.getElementById("txt2");
ExpandedSubBlockStart.gifContractedSubBlock.gif
if(deCode)dot.gif{
InBlock.gif  txt2.value 
= urlDecode(txt1.value);
ExpandedSubBlockStart.gifContractedSubBlock.gif}
elsedot.gif{
InBlock.gif  txt2.value 
= urlEncode(txt1.value);
ExpandedSubBlockEnd.gif}

ExpandedBlockEnd.gif}

None.gif
function urlDecode(str)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif
if("undefined" == typeof decodeURIComponent)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif  
return unescape(str).replace(/\+/g, ' ').replace(/%2B/g,'+');
ExpandedSubBlockStart.gifContractedSubBlock.gif   }
 else dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//*just use my self decode script*/
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//*return decodeURIComponent(str.replace(/\+/g, ' ').replace(/%2B/g,'+'));*/
InBlock.gif    
return unescape(str).replace(/\+/g, ' ').replace(/%2B/g,'+');
ExpandedSubBlockEnd.gif  }

ExpandedBlockEnd.gif}

None.gif
function urlEncode(str)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif
var i,c,ret="",strSpecial="!\"#$%&'()*+,/:;<=>?@[\]^`dot.gif{|}~%";
InBlock.giffor(i=0;i<str.length;i++)
InBlock.gif{
InBlock.gif  c=str.charAt(i);
InBlock.gif  if(c==
" ")
InBlock.gif  ret+=
"+";
InBlock.gif  else if(strSpecial.indexOf(c)!=-1)
InBlock.gif   ret+=
"%"+str.charCodeAt(i).toString(16);
InBlock.gif  else
InBlock.gif  ret+=c;
InBlock.gif}
InBlock.gifreturn ret;
InBlock.gif};
InBlock.gif</script>
InBlock.gif</head>
InBlock.gif<body>
InBlock.gif<div id=
"output">
InBlock.gif  Source:<br />
InBlock.gif    <textarea name=
"txt1" cols="52" rows="12"></textarea><br />
InBlock.gif  Destination:<br />
InBlock.gif  <textarea name=
"txt2" cols="52" rows="12"></textarea><br />
InBlock.gif  <input name=
"Decode" type="button" value="Decode" οnclick="doCode(true);" />
InBlock.gif  <input name=
"Encode" type="button" value="Encode" οnclick="doCode(false);" />
InBlock.gif</div>
InBlock.gif</body>
InBlock.gif</html>
posted on 2007-04-24 22:16 黄尚 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/afxcn/archive/2007/04/24/725916.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值