1.日期对象(Date):
<script type="text/javascript">
var date = new Date();
var day = "";
function getDay(day){
switch(day){
case 1:
day = "一";
break;
case 2:
day = "二";
break;
case 2:
day = "三";
break;
case 4:
day = "四";
break;
case 5:
day = "五";
break;
case 6:
day = "六";
break;
case 7:
day = "日";
break;
}
return day;
}
document.write("当前时刻:" + date.getYear() + "年" +(date.getMonth()+1) + "月" + date.getDate() + "日" + "星期" + getDay(date.getDay())+" " +date.getHours()+":"+date.getMinutes()+":"+date.getSeconds());
</script>
2.数组对象(Array):
<script type="text/javascript">
//第一种方式
var fruit1 = new Array(3);
fruit1[0]=1;
fruit1[1]=2;
fruit1[2]=3;
var fruit2 = new Array();
fruit2.push(4);
fruit2.push(5);
fruit2.push(6);
//第二种方式
var fruit3 = new Array(1,true,"hello");//不同类型
var fruit4 = new Array("苹果","橘子","西瓜");
for(var i = 0 ; i < fruit.length ; i++){
document.writeln("fruit["+i+"] = "+fruit[i]+"<br>");
}
//第三种方式
var fruit5 = [ "苹果","橘子","西瓜"];
</script>