定義和用法
把數(shù)組轉(zhuǎn)換為本地字符串。
語法
arrayObject.toLocaleString()
返回值
arrayObject 的本地字符串表示。
說明
首先調(diào)用每個數(shù)組元素的 toLocaleString() 方法,然后使用地區(qū)特定的分隔符把生成的字符串連接起來,形成一個字符串。
實例
<script type="text/javascript"> var arr = new Array(3) arr[0] = "George" arr[1] = "John" arr[2] = "Thomas" document.write(arr.toLocaleString()) </script>
輸出:
George, John, Thomas
此代碼用來學(xué)習(xí)JavaScript的toLocaleString方法,使用JS的toLocaleString方法獲取當前的電腦時間,并將結(jié)果:“當前本地系統(tǒng)時間為:”顯示在網(wǎng)頁的主體Body區(qū)域內(nèi)。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312"> <title>使用toLocaleString獲取本地時間</title> </head> <body background="temp.JPG"> <script language="javascript"> var now = new Date(); hours = now.getHours(); if (hours < 25) { document.write("<font size = 6pt face = 黑體 color = ff9900>"+"當前本地系統(tǒng)時間為:"+now.toLocaleString()+"</font>"); } </script> </body> </html>
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com