js常用系統(tǒng)函數(shù)用法實(shí)例分析
本文實(shí)例講述了js常用系統(tǒng)函數(shù)用法。分享給大家供大家參考。
具體代碼如下:
<head>
</head>
<body>
<script type="text/javascript">
//1. escape()函數(shù),把字符串轉(zhuǎn)成各計算機(jī)平臺通用的unicode編碼;解碼(轉(zhuǎn)回去)則用enescape()。
var str = '王美人';
document.write(escape(str));
document.write("<br />");
//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. 判斷一個值/變量值,是不是非數(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程序設(shè)計有所幫助。
相關(guān)文章
js實(shí)現(xiàn)鼠標(biāo)觸發(fā)圖片抖動效果的方法
這篇文章主要介紹了js實(shí)現(xiàn)鼠標(biāo)觸發(fā)圖片抖動效果的方法,通過定時器定時遞歸調(diào)用rattleimage函數(shù)實(shí)現(xiàn)抖動效果,非常實(shí)用,具有一定參考借鑒價值,需要的朋友可以參考下2015-02-02

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