jason_009

导航

表格隔行显示不同颜色,mouseover时高亮显示的javascript代码

 1     <script type="text/javascript">
2 $(function() {
3 //changecolor("表格名称","奇数行背景","偶数行背景","鼠标经过背景","点击后背景");
4 if ($("#changecolor").length > 0) {
5 senfe("changecolor", "#f8fbfc", "#e5f1f4", "#ecfbd4", "#bce774");
6 }
7 });
8
9 //********************** 表格隔行变色-开始 ***************************
10 function senfe(o, a, b, c, d) {
11 var t = document.getElementById(o).getElementsByTagName("tr");
12 for (var i = 0; i < t.length; i++) {
13 t[i].style.backgroundColor = (t[i].sectionRowIndex % 2 == 0) ? a : b;
14
15 t[i].onmouseover = function() {
16 if (this.x != "1") {
17 if (this.style.backgroundColor != d) this.style.backgroundColor = c;
18 }
19 }
20 t[i].onmouseout = function() {
21 if (this.x != "1") {
22 if (this.style.backgroundColor != d) this.style.backgroundColor = (this.sectionRowIndex % 2 == 0) ? a : b;
23 }
24 }
25 }
26 }
27 //********************** 表格隔行变色-结束 ***************************
28 </script>

开始时调用JQuery,在ready的时候将调用隔行变色的函数,changecolor为表格的id.

posted on 2012-02-14 01:00  jason_009  阅读(255)  评论(0编辑  收藏  举报