<script type="text/javascript" language="javascript"> //遍历数组 var arr = ["aaa","bbb","ccc"];//创建一个数组 //JavaScript增强for循环中遍历数组时遍历的是数组下标而不是数组元素(java中增强型for语句遍历的是元素,在c#是foreach遍历的也是元素) /*for(var index in arr){ alert(index); alert(arr[index]); }*/ //遍历对象的属性 var object = {name:"张三",age:23,sex:"男"}; /*for(var pro in object){ alert(object[pro]); }*/ //with语句 var date = new Date(); with(date){//使用了with,就可以将date.getYear()的date省略 alert((getYear()+1900)+"/"+ getMonth()+"/"+getDate()); } </script>
|
请发表评论