WEB开发网
开发学院网页设计JavaScript JavaScript方法和技巧大全——基础知识(3) 阅读

JavaScript方法和技巧大全——基础知识(3)

 2010-09-14 13:40:03 来源:WEB开发网   
核心提示:指定次数循环1<script>2 var myArray = new Array(3);3 myArray[0] = “Item 0”;4 myArray[1] = “Item 1”;5 myArray[2] = “Item 2”;6

指定次数循环

1<script>
2 var myArray = new Array(3);
3 myArray[0] = “Item 0”;
4 myArray[1] = “Item 1”;
5 myArray[2] = “Item 2”;
6 for (i = 0; i < myArray.length; i++) { 
7 document.write(myArray[i] + “<br>”);
8 }
9</script>

设定将来执行

1<script>
2 function hello() { 
3 window.alert(“Hello”);
4 }
5 window.setTimeout(“hello()”,5000);
6</script>

定时执行函数

1<script>
2 function hello() { 
3 window.alert(“Hello”);
4 window.setTimeout(“hello()”,5000);
5 }
6 window.setTimeout(“hello()”,5000);
7</script>

取消定时执行

1<script>
2 function hello() { 
3 window.alert(“Hello”);
4 }
5 var myTimeout = window.setTimeout(“hello()”,5000);
6 window.clearTimeout(myTimeout);
7</script>

在页面卸载时候执行函数

1<body onUnload=”functionName();”>
2 Body of the page
3</body>

Tags:JavaScript 方法 技巧

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接