js表格隔行換色和hover效果

來源:互聯網
上載者:User

標籤:

<!--js效果-->

<script src="js/jquery.min.js" language="javascript"></script>

<script>

$(document).ready(function(){
///////datagrid選中行變色與滑鼠經過行變色///////////////
var dtSelector = ".list";
var tbList = $(dtSelector);

tbList.each(function() {
var self = this;
$("tr:even:not(:first)", $(self)).addClass("normalEvenTD"); // 從標題行下一行開始的奇數行,行數:(1,3,5...)
$("tr:odd", $(self)).addClass("normalOddTD"); // 從標題行下一行開始的偶數行,行數:(2,4,6...)

// 滑鼠經過的行變色
$("tr:not(:first)", $(self)).hover(
function () { $(this).addClass(‘hoverTD‘);$(this).removeClass(‘table-td-content‘); },
function () { $(this).removeClass(‘hoverTD‘);$(this).addClass(‘table-td-content‘); }
);

// 選擇行變色
$("tr", $(self)).click(function (){
var trThis = this;
$(self).find(".trSelected").removeClass(‘trSelected‘);
if ($(trThis).get(0) == $("tr:first", $(self)).get(0)){
return;
}
$(trThis).addClass(‘trSelected‘);
});
});
});

</script>

<!--表格代碼-->

<table width="100%" class="list" style="word-break: break-all" border="0"
align="center" cellpadding="0" cellspacing="1" bgcolor="#e4e5e5">
<tr class="table-tr-title">
<td width="5%">姓名</td>
<td width="5%">授權層級</td>
<td width="5%">經銷商手機號</td>
</tr>
<tr class="table-tr-content">
<td width="5%">談重海</td>
<td width="5%">一級代理</td>
<td width="5%">156230152416</td>
</tr>
<tr class="table-tr-content">
<td width="5%">資料</td>
<td width="5%">資料</td>
<td width="5%">資料</td>
</tr>
<tr class="table-tr-content">
<td width="5%">資料</td>
<td width="5%">資料</td>
<td width="5%">資料</td>
</tr>
<tr class="table-tr-content">
<td width="5%">資料</td>
<td width="5%">資料</td>
<td width="5%">資料</td>
</tr>
<tr class="table-tr-content">
<td width="5%">資料</td>
<td width="5%">資料</td>
<td width="5%">資料</td>
</tr>
</table>

<!--css樣式表-->

.table-tr-title{ font-weight:bold;
height: 26px;
font-size: 16px; font-family:"微軟雅黑"; line-height:36px;
text-align: center;
}
.table-tr-content{line-height:32px; font-size:14px; font-family:"微軟雅黑";
height: 18px; color:#676767;
background: #FFFFFF;
text-align: center;
font-size: 12px;
}
.normalEvenTD{
background: #e9e8e8;
}
.normalOddTD{
background: #FFFFFF;
}
.hoverTD{
background-color: #d2d0d0; 
height: 18px;
text-align: center;
font-size: 12px;
}
.trSelected{
background-color: #51b2f6;
height: 18px;
text-align: center;
font-size: 12px;
}

js表格隔行換色和hover效果

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.