1 <script language="javascript">
2 function fnTableOver() {
3 var oTable = document.getElementById("tableList");
4 if (oTable!=null) {
5 for (var i=1;i<oTable.rows.length-1;i++) {
6 oTable.rows[i].bgColor="#E6F2FF";
7 oTable.rows[i].onmouseover = function () { this.bgColor="#D2E8FF";}
8 oTable.rows[i].onmouseout = function() { this.bgColor="#E6F2FF"}
9 }
10 }
11 }
12
13 function domLoad() {
14 if (arguments.callee.done) return;
15 arguments.callee.done = true;
16
17 //add domLoad code here
18 fnTableOver();
19 }
20
21 /* for Mozilla */
22 if (document.addEventListener) {
23 document.addEventListener("DOMContentLoaded", domLoad, null);
24 }
25
26 /* for other browsers */
27 window.onload = domLoad;
28 </script>
29
30 <script language="javascript" defer>
31 /* for IE */
32 /*@cc_on
33 @if (@_win32)
34 domLoad();
35 @end
36 @*/
37 </script>
实际使用的是这个代码。还没有仔细测试完成,等。2 function fnTableOver() {
3 var oTable = document.getElementById("tableList");
4 if (oTable!=null) {
5 for (var i=1;i<oTable.rows.length-1;i++) {
6 oTable.rows[i].bgColor="#E6F2FF";
7 oTable.rows[i].onmouseover = function () { this.bgColor="#D2E8FF";}
8 oTable.rows[i].onmouseout = function() { this.bgColor="#E6F2FF"}
9 }
10 }
11 }
12
13 function domLoad() {
14 if (arguments.callee.done) return;
15 arguments.callee.done = true;
16
17 //add domLoad code here
18 fnTableOver();
19 }
20
21 /* for Mozilla */
22 if (document.addEventListener) {
23 document.addEventListener("DOMContentLoaded", domLoad, null);
24 }
25
26 /* for other browsers */
27 window.onload = domLoad;
28 </script>
29
30 <script language="javascript" defer>
31 /* for IE */
32 /*@cc_on
33 @if (@_win32)
34 domLoad();
35 @end
36 @*/
37 </script>
参考:
持续讨论 javascript 如何控制优化页面 js 加载顺序
[转载] window.onload 关于页面加载完毕的问题