<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS中的常见函数</title>
</head>
<body>
<script type="text/javascript">
var url="http://www.baidu.com/?123 .@3#$%/, / ? : @ & = + $ #/- _ . ! ~ * ' ( )/* @ - —— + . /";
//alert(url);
//对URL进行编码的函数codeURI与decodeURI
//这些符号不转换: , / ? : @ & = + $ #
var eurl=encodeURI(url);
document.write(eurl+'<br />');
document.write(decodeURI(eurl)+'<br />');
document.write('<hr color="red"/>');
//对URI进行编码的函数encodeURIComponcent与decodeURIComponcent
//以下符号不转换: - _ . ! ~ * ' ( )
var url2="http://www.bing.com/a-b_c.d!!~/%&:123?"
var eurl2=encodeURIComponent(url2);
document.write(eurl2+'<br />');
document.write(decodeURIComponent(eurl2)+'<br />');
document.write('<hr color="red"/>')
//对字符串进行编码用escape
//对以下符号不转换:* @ - —— + . / 。
var url3=escape(url);
document.write(url3+'<br />');
document.write(unescape(url3)+'<br />');
document.write('<hr color="red"/>');
//Number()字符转数字,String()转换成字符串如果不能转换,输出为NaN
var a=123, b="abc", c='123def.123', d=true;
document.write(Number(a)+'<br />');
document.write(Number(b)+'<br />');
document.write(Number(c)+'<br>');
document.write('从1970年1月1日到现在毫秒数为:'+Number(new Date)+'<br/>');
document.write('现在的时间是:'+String(new Date)+'<br />');
document.write(String(a+' '+b+' '+c+' '+d));
</script>
</body>
</html>