JS的全局函数


JS的全局函数

    全局属性和函数可用于所有内建的 JavaScript 对象


 

关于编码和解码的一组方法:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>全局函数</title>
        <script>
            var str = "张三";
            //alert(encodeURI(str));//%E5%BC%A0%E4%B8%89
            //alert(encodeURIComponent(str));//%E5%BC%A0%E4%B8%89
            
            //alert(decodeURI(encodeURI(str)));//张三
            //alert(decodeURIComponent(encodeURIComponent(str)));//张三
            
            var str1 = "http://www.itheima.cn";
            //alert(encodeURI(str1));//http://www.itheima.cn
            //alert(encodeURIComponent(str1));//http%3A%2F%2Fwww.itheima.cn
            
            //alert(decodeURI(encodeURI(str1)));//http://www.itheima.cn
            //alert(decodeURIComponent(encodeURIComponent(str1)));//http://www.itheima.cn
            
            var str2 = "alert('abc')";
            //alert(str2);
            eval(str2);
            
        </script>
    </head>
    <body>
    </body>
</html>

在本例中,我们将使用 parseInt() 来解析不同的字符串:

parseInt("10");			//返回 10               默认十进制
parseInt("19",10);		//返回 19 (10+9)        第二个参数10,表示十进制
parseInt("11",2);		//返回 3 (2+1)          第二个参数2,表示二进制
parseInt("17",8);		//返回 15 (8+7)         第二个参数8,表示八进制
parseInt("1f",16);		//返回 31 (16+15)
parseInt("010");		//未定:返回 10 或 8


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM