当前位置:编程学习 > JAVA >>

javascript复习3:Date && Array

[html] 
<input type="button" onclick="startTime()" value="计时" /><br />  
<div id="txt"></div><br />  
[javascript] view plaincopyprint?
var d=new Date()  
var weekday=new Array(7)  
weekday[0]="星期日"  
weekday[1]="星期一"  
weekday[2]="星期二"  
weekday[3]="星期三"  
weekday[4]="星期四"  
weekday[5]="星期五"  
weekday[6]="星期六"  
  
document.write(d.getFullYear())  
document.write("今天是" + weekday[d.getDay()])  
 
[javascript] 
function startTime()  
{  
var today=new Date()  
var h=today.getHours()  
var m=today.getMinutes()  
var s=today.getSeconds()  
// add a zero in front of numbers<10  
m=checkTime(m)  
s=checkTime(s)  
document.getElementById('txt').innerHTML='<div>'+h+":"+m+":"+s+"</div>"  
t=setTimeout('startTime()',500)  
}  
  
function checkTime(i)  
{  
if (i<10)   
  {i="0" + i}  
  return i  
}  
 
[javascript]  
var arr = new Array(3)  
arr[0] = "George"  
arr[1] = "John"  
arr[2] = "Thomas"  
  
var arr2 = new Array(3)  
arr2[0] = "James"  
arr2[1] = "Adrew"  
arr2[2] = "Martin"  
  
document.write(arr.concat(arr2))  
[javascript] 
var arr = new Array(3);  
arr[0] = "George"  
arr[1] = "John"  
arr[2] = "Thomas"  
document.write(arr.join());  
document.write("<br />");  
document.write(arr.join("."));  
[javascript]  
var arr = new Array(6)  
arr[0] = "George"  
arr[1] = "John"  
arr[2] = "Thomas"  
arr[3] = "James"  
arr[4] = "Adrew"  
arr[5] = "Martin"  
document.write(arr + "<br />")  
document.write(arr.sort())  
[javascript] 
function sortNumber(a, b)  
{  
return a - b  
}  
var arr = new Array(6)  
arr[0] = "10"  
arr[1] = "5"  
arr[2] = "40"  
arr[3] = "25"  
arr[4] = "1000"  
arr[5] = "1"  
document.write(arr + "<br />")  
document.write(arr.sort(sortNumber))  
 
补充:web前端 , JavaScript ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,