JS简单入门教程

时间:2022-05-08 16:02:08

JS简单教程

使用方法:放到任意html页面的head标签下

Test1方法弹出当前时间对话框

Test2方法for循环输出

Test3方法for(…in…)输出数组内容

<script type="text/javascript">

var a = 10;

var b = 11;

if (a < b)

{

document.write("hello man")

}

else

{

document.write("hello world");

}

function test1()

{

var mydata = new Date();

//x = a * b;

alert(mydata);

}

function test2(a)

{

for(var i=0;i<a;i++)

{

document.write("The number is" + i);

}

}

function test3()

{

var a;

var listtest = new Array();

listtest[0] = "a1";

listtest[1] = "a2";

listtest[2] = "a3";

for(a in listtest)

{

document.write(listtest[a]+"<br/>");

}

}

</script>