-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex4.html
97 lines (97 loc) · 2.16 KB
/
index4.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>根据某种条件反复设置某种样式</title>
<style>
body{
font-family: "Arial";
background-color: #fff;
color: #000;
}
table{
margin: auto;
border: 1px solid #699;
}
caption{
margin: auto;
padding: .2em;
font-size: 1.2em;
font-weight: bold;
}
th{
font-weight: normal;
font-style: italic;
text-align: left;
border: 1px dotted #699;
background-color: #9cc;
color: #000;
}
th,td{
width: 10em;
padding: .5em;
}
/* 被JavaScript脚本能代替 */
/* tr:nth-child(odd) {background-color: #ffc;}
tr:nth-child(even){background-color: #fff;} */
</style>
</head>
<body>
<table>
<caption>Itinerary</caption>
<thead>
<tr>
<th>When</th>
<th>Where</th>
</tr>
</thead>
<tbody>
<tr>
<td>June 9th</td>
<td>Portland,<abbr title="Oregon">OR</abbr></td>
</tr>
<tr>
<td>June 10th</td>
<td>Seattle,<<abbr title="Washington">WA</abbr>></td>
</tr>
<tr>
<td>June 12th</td>
<td>Sacramento,<<abbr title="California">CA</abbr>></td>
</tr>
</tbody>
</table>
<script type="text/javascript">
/*通用性函数*/
function stripeTables() {
if(!document.getElementsByTagName) return false;
var tables = document.getElementsByTagName('table');
var odd,rows;
for(var i = 0; i < tables.length; i++){
odd = false;
rows = tables[i].getElementsByTagName('tr');
for(var j = 0; j<rows.length; j++){
if(odd == true){
rows[j].style.backgroundColor = '#ffc';
odd = false;
}else{
odd = true;
}
}
}
}
/*功能性函数*/
function addLoadEvent(func){
var oldEvent = window.onload;
if(typeof(oldEvent) != 'function' ){
window.onload = func();
}else{
window.onload = function(){
func();
oldEvent();
}
}
}
addLoadEvent(stripeTables);
</script>
</body>
</html>