国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

JavaScript中變量的幾個(gè)相關(guān)函數(shù)

判斷變量的數(shù)據(jù)類型:

typeof()

  • 使用typeof(),可以測試一個(gè)變量的類型。

  • typeof()測試的結(jié)果是一個(gè)類型字符串。

typeof()的結(jié)果字符串有幾種情況:?“string”?、 “number”?、?“boolean”?、?“undefined”?、 “object”?、?“function”

另外:null、對象、數(shù)組這三種類型,都將返回 “object”。

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>php.cn</title>
        <script>
            var x1 = "abc";     //string
            var x2 = 110;       //number
            var x3 = true;      //boolean
            var x4;             //undefined
            var x5 = null;      //object        
        //使用typeof()判斷變量的數(shù)據(jù)類型
        var result = typeof(x5);
        //輸出變量的類型和結(jié)果
        document.write(x5+"的數(shù)據(jù)類型為:"+result);
        </script>
    </head>
    <body>
    </body>
</html>

注:大家可以嘗試判斷其他幾個(gè)變量的數(shù)據(jù)類型


從字符串中提取整數(shù)和浮點(diǎn)數(shù)函數(shù)

parseInt()系統(tǒng)函數(shù)、全局函數(shù)

功能:在一個(gè)字符串中,從左往右提取整型。如果遇到非整型的內(nèi)容,則停止提取,并返回結(jié)果。

注:如果第一個(gè)字符就是非整數(shù),則立即停止,并返回NaN。

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>php.cn</title>
        <script>
            document.write(parseInt("500eps")+"<br/>");
            document.write(parseInt("500.88")+"<br/>");
            document.write(parseInt("a120px")+"<br/>");
        </script>
    </head>
    <body>
    </body>
</html>

parseFloat()系統(tǒng)函數(shù)、全局函數(shù)

功能:在一個(gè)字符串中,從左往右提取浮點(diǎn)型;遇到非浮點(diǎn)型內(nèi)容,則停止提取,并返回結(jié)果。

注:如果第一個(gè)字符是非浮點(diǎn)型,則立即停止,并返回NaN。

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>php.cn</title>
        <script>
            document.write(parseFloat("500eps")+"<br/>");
            document.write(parseFloat("500.88")+"<br/>");
            document.write(parseFloat("a120px")+"<br/>");
        </script>
    </head>
    <body>
    </body>
</html>



繼續(xù)學(xué)習(xí)
||
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script> document.write(parseInt("500eps")+"<br/>"); document.write(parseInt("500.88")+"<br/>"); document.write(parseInt("a120px")+"<br/>"); </script> </head> <body> </body> </html>
提交重置代碼