-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathindex.html
107 lines (105 loc) · 3.8 KB
/
index.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
98
99
100
101
102
103
104
105
106
107
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>隔行换色鼠标经过换色</title>
<link rel="stylesheet" type="text/css" href="../../css/bootstrap.min.css" media="all"/>
<link rel="stylesheet" type="text/css" href="../../css/bootstrap-theme.min.css" media="all"/>
<link rel="stylesheet" type="text/css" href="../../css/reset.css" media="all"/>
<style type="text/css">
.demo{ width:600px;margin:50px auto; text-align:left; padding:0; }
.list{ color:#2a6496;}
.list li{ position:relative; width:320px;list-style:decimal inside;line-height:35px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
.list a{font-size:18px;}
.tip{position:absolute;left: 0;display:none;color:#fff;background:rgba(0,0,0, 0.6); line-height:25px;font-size:12px;padding:2px 5px;border-radius:5px;z-index:1}
.ellipsis{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
.table{border-collapse:collapse; border:1px solid #ccc;}
.table th, .table td{ border:1px solid #ccc;}
.table th{background: #f5f5f5;}
.table tr.even td{background: #dff0d8;}
.table tr.hover td{background: #fcf8e3;}
.table tr.on td{background: #d9edf7;}
</style>
</head>
<body>
<div id="div" class="demo">
<input type="text" name="" id="txt"/><input id="add" type="button" value="add"/>
<input id="del" type="button" value="del"/>
<table class="table">
<tr>
<th>表头内容</th>
<th>表头内容</th>
<th>表头内容</th>
</tr>
<tr>
<td>表格内容1</td>
<td>表格内容2</td>
<td>表格内容3</td>
</tr>
<tr>
<td>表格内容1</td>
<td>表格内容2</td>
<td>表格内容3</td>
</tr>
<tr>
<td>表格内容1</td>
<td>表格内容2</td>
<td>表格内容3</td>
</tr>
<tr>
<td>表格内容1</td>
<td>表格内容2</td>
<td>表格内容3</td>
</tr>
<tr>
<td>表格内容1</td>
<td>表格内容2</td>
<td>表格内容3</td>
</tr>
</table>
</div>
<script>
(function(){
var div = document.getElementById('div');
var tab = div.getElementsByTagName('table')[0];
var tr = tab.getElementsByTagName('tr');
var tmp = '';
var k = 0;
for(var i = 0; i < tr.length; i++){
if(i % 2 == 0){
tr[i].className = 'even';
}
if(i > 0){
tr[i].index = i;
tr[i].onmouseover = function(){
if(this.index == k || this.className.search(/on/) != -1){
return;
}
tmp = this.className;
this.className = 'hover';
}
tr[i].onmouseout = function(){
if(this.index == k || this.className.search(/on/) != -1){
return;
}
this.className = tmp;
}
tr[i].onclick = function(e){
k = this.index;
if(!+this.getAttribute('data-on')){
this.setAttribute('data-on', 1);
this.className = 'on';
} else {
if(this.index % 2 == 0){ this.className = 'even'; }
this.className = this.className.replace(/on/g, '');
this.setAttribute('data-on', 0);
}
}
}
var add = document.getElementById('add');
var del = document.getElementById('del');
}
}());
</script>
</body>
</html>