我們先來看一下min函數(shù)的基本語法
Math.min(value1,value2,...)
Value1,Value2,……:傳遞到math.min()函數(shù)的值,用于查找最小值。
我們下面來看具體示例
代碼如下
參數(shù)是正數(shù)和負(fù)數(shù)時(shí):
代碼如下
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> </head> <body> <script type="text/javascript"> document.write("Output : " + Math.min(10, 32, 2)); document.write("Output : " + Math.min(-10, -32, -1)); </script> </body> </html>
執(zhí)行結(jié)果如下:
Output : 1 Output : -32
沒有參數(shù)傳遞時(shí)
代碼如下:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> </head> <body> <script type="text/javascript"> document.write("Output : " + Math.min()); </script> </body> </html>
執(zhí)行結(jié)果如下
Output : -Infinity
當(dāng)參數(shù)中有參數(shù)無法轉(zhuǎn)換為數(shù)字時(shí):
代碼如下
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> </head> <body> <script type="text/javascript"> document.write("Output : " + Math.min(10,2,NaN)); </script> </body> </html>
執(zhí)行結(jié)果如下
Output : NaN
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com