日期:2014-05-16  浏览次数:20443 次

js例子
数组
var ary=new Array();
ary[0]="yes";
ary[1]="no";
//document.write(ary.toString());

var ary=["red","yellow","blue"];
document.write(ary+"<br/>");
document.write(ary.length);


//用for--in --迭代
for(var index in ary){
document.write("&nbsp;"+ary[index]+"&nbsp;");
}


//拼接
document.write(ary.join("-")+"<br/>");


//反转,对其本身作改变
document.write(ary.reverse()+"<br/>");


//排序,按ASII码
ary.sort();

document.write(ary);
--------------------------------

<script>
function mycompare(x,y)
{
var result=0;
var a=parseInt(x);
var b=parseInt(y);
if(a>b)
{
result=1;
}
else if(a<b)
{
result=-1;
}

return result;

}
var ary=new Array();
var ary=["ww","yy","aaa"];
ary[0]="zs";
ary[1]="ls";
document.write(ary+"<br/>");
ary[2]="bbb";
document.write(ary.length);

for(var index in ary)
{
  document.write(ary[index]+"<br/>")
}
//数组元素拼接
document.write(ary.join()+"<br/>");
//数组元素转置
ary.reverse();

document.write(ary+"<br/>");

var ary1=[2,20,4,5,12];
document.write(ary1+"<br/>");
//排序
ary1.sort(mycompare);
document.write(ary1+"<br/>");

//数组拼接
var ary2=["a","b","c"];
var ary3=["e","f"];

var ary4=ary2.concat(ary3,ary3);
var ary5=ary4.concat("g","h",ary3);
document.write(ary5+"<br/>")

//返回选定的元素

document.write( ary5.slice(2,80)+"<br/>");

//替换元素

var ary6=["zs","ls","ww"];

document.write(ary6+"<br/>")

ary6.splice(1,1,"adsf","adsf");
document.write(ary6+"<br/>")

document.write(ary6.pop()+"<br/>");

document.write(ary6);
</script>
--------------------------------

锯齿数组
var arys=[["SQL SERVER","C# OOP"],["WEB FORM","HTML/CSS/JAVASCRIPT","ORACLE","ADO.NET"],["ASP.NET","LINQ"]];
document.write(11+"----------------------------<br/>");

for(var index in arys){
document.write(arys[index]+"<br/>");
}

document.write("<hr/>");
for(var index in arys){
for(var i in arys[index]){
document.write("第"+(parseInt(index)+1)+"个子数组里面的元素为:"+arys[index][i]+"<br/>");
}
document.write("<hr/>");
}


--------------------------------

--------------------------------





时间
var now=new Date();
document.write(now.toTimeString()+"<br/>");
document.write(now.toLocaleString()+"<br/>");
document.write(now.toDateString()+"<br/>");

var now = new Date();
var year = now.getYear();
var month = now.getMonth() + 1;
var date = now.getDate();
var day = now.getDay();
var hour = now.getHours();
var minute = now.getMinutes();
var second = now.getSeconds();
var dayStr = "日一二三四五六";
var strDateTime = "今天日期是:"  +year + "年" + month + "月" + date + "日 星期" + dayStr.charAt(day) + " 现在时间是:" + hour + "时" + minute + "分" + second + "秒";
document.write(strDateTime+"<br/>");

--------------------------------
<html>

<head>

<title>网站地址管理</title>

<script type="text/javascript">
    var stopid;
    function timeGo(){
        var time=new Date();
        do