函数描述说明:
函数 | 说明 |
---|---|
eval() | 求字符串中表达式的值 |
isFinite() | 判断一个数值是否为无穷大 |
inNaN() | 判断一个数值是否为NaN |
parseInt() | 将字符型转换为整型 |
parseFloat() | 将字符型转化为浮点型 |
encodeURI() | 将字符型转化为有效的URI |
encodeURIComponent() | 将字符型转化为有效的URI组件 |
decodeURI() | 对encodeURI()编码的文本进行解码 |
decodeURIComponent() | 对decodeURIComponent()编码的文本进行解码 |
代码片段实例:
<html>
<meta charset="utf-8">
<script type="text/javascript">
//parseInt()
var num1 = "123abc";
var num2 = "abc123";
document.write("1、parseInt():<br>");
document.write("123abc = "+parseInt(num1)+"<br>");
document.write("abc123 = "+parseInt(num2)+"<br><br>");
//parseFloat()
var num3 = "123.123abc";
document.write("2、parseFloat():<br>");
document.write("123.123abc = "+parseFloat(num3)+"<br><br>");
//isNaN()
document.write("3、isNaN():<br>");
document.write("123.123abc = "+isNaN(parseFloat(num3))+"<br>");
document.write("abc123 = "+isNaN(+parseInt(num2))+"<br><br>");
//isFinite()
document.write("4、isFinite():<br>");
document.write("1/0的结果:"+isFinite(1/0)+"<br><br>");
//encodeURI()
document.write("5、encodeURI():<br>");
document.write("转化为网络资源网址:"+encodeURI("http://www.baidu.com?name=ty库10086")+"<br><br>");
//decodeURI()
var str = encodeURI("http://www.baidu.com?name=ty库10086");
document.write("6、decodeURI():<br>");
document.write("转化为网络资源地址的字符串为:"+decodeURI(str)+"<br><br>");
</script>
</html>
结果显示: