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