日期:2014-05-17 浏览次数:20491 次
<script>
var URLEncode = {
map: {
'0': '0',
'1': '1',
'2': '2',
'3': '3',
'4': '4',
'5': '5',
'6': '6',
'7': '7',
'8': '8',
'9': '9',
'10': 'A',
'11': 'B',
'12': 'C',
'13': 'D',
'14': 'E',
'15': 'F'
},
toHex: function(num) {
var s = [];
while ( num >= 16 ) {
s.unshift( URLEncode.map[num % 16] );
num = Math.floor( num / 16 );
}
s.unshift( URLEncode.map[num] );
return '%' + s.join('');
},
exec: function(url) {
var exp = /^([a-z]+:\/\/)([^/]*)(.*)/;
var a, b, c, len, arr;
arr = url.match(exp);
a = arr[1];
b = arr[2];
c = arr[3];
len = b.length;
for (var i = 0; i < len; i++) {
a += URLEncode.toHex(b.charAt(i).charCodeAt());
}
return a + (c.length ? c : '/');
}
}
var teststr = 'http://baidu.com';
alert('加密前: ' + teststr);
alert('加密后: ' + URLEncode.exec(teststr));
alert('解密后:' + unescape(URLEncode.exec(teststr)));
</script>
var URLEncode = {
map: {
'0': '0',
'1': '1',
'2': '2',
'3': '3',
&nbs