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

转载于:https://www.cnblogs.com/fujiayao/p/8835604.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值