本文實(shí)例講述了js常用系統(tǒng)函數(shù)用法。分享給大家供大家參考。
具體代碼如下:
//2. 字符串轉(zhuǎn)化為整型,或轉(zhuǎn)化為浮點(diǎn)型。如果原字符串a(chǎn)ge不是以數(shù)字開頭,結(jié)果則是NaN。
var age = "26.9hellow world";
document.write(parseInt(age));//parseInt()函數(shù)
document.write("<br />");
document.write(parseFloat(age));//parseFloat()函數(shù)
document.write("<br />");
//3. 判斷一個(gè)值/變量值,是不是非數(shù)字。
var num = "30.9abc";
if(isNaN(num)){
document.write("num是一個(gè)非數(shù)字");
}else{
document.write("num是一個(gè)數(shù)字");
}
document.write("<br />");
//4. 判斷一個(gè)值/變量值,是不是有窮的
var result = 10/0;
if(isFinite(result)){
document.write("result變量的值有窮的");
}else{
document.write("result變量的值無窮的");
}
</script>
</body>
</html>
希望本文所述對大家的javascript程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答