js常用系統(tǒng)函數(shù)用法實例分析
本文實例講述了js常用系統(tǒng)函數(shù)用法。分享給大家供大家參考。
具體代碼如下:
<head>
</head>
<body>
<script type="text/javascript">
//1. escape()函數(shù),把字符串轉(zhuǎn)成各計算機平臺通用的unicode編碼;解碼(轉(zhuǎn)回去)則用enescape()。
var str = '王美人';
document.write(escape(str));
document.write("<br />");
//2. 字符串轉(zhuǎn)化為整型,或轉(zhuǎ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. 判斷一個值/變量值,是不是非數(shù)字。
var num = "30.9abc";
if(isNaN(num)){
document.write("num是一個非數(shù)字");
}else{
document.write("num是一個數(shù)字");
}
document.write("<br />");
//4. 判斷一個值/變量值,是不是有窮的
var result = 10/0;
if(isFinite(result)){
document.write("result變量的值有窮的");
}else{
document.write("result變量的值無窮的");
}
</script>
</body>
</html>
希望本文所述對大家的javascript程序設計有所幫助。
相關文章

單行 JS 實現(xiàn)移動端金錢格式的輸入規(guī)則