jquery實(shí)現(xiàn)效果比較好的table選中行顏色
更新時(shí)間:2014年03月25日 18:01:08 作者:
這篇文章主要介紹了jquery table選中行顏色實(shí)現(xiàn)代碼,需要的朋友可以參考下
jquery table選中行顏色(效果更好)
<html>
<head>
<style type="text/css">
.table-tr-title{
height: 26px;
font-size: 12px;
text-align: center;
}
.table-tr-content{
height: 18px;
background: #FFFFFF;
text-align: center;
font-size: 12px;
}
.normalEvenTD{
background: #DFD8D8;
}
.normalOddTD{
background: #FFFFFF;
}
.hoverTD{
background-color: #eafcd5;
height: 18px;
text-align: center;
font-size: 12px;
}
.trSelected{
background-color: #51b2f6;
height: 18px;
text-align: center;
font-size: 12px;
}
</style>
</head>
<body>
<table width="99%" class="list" style="word-break: break-all" border="0"
align="center" cellpadding="0" cellspacing="1" bgcolor="#c0de98">
<tr class="table-tr-title">
<td width="5%">標(biāo)題</td>
<td width="5%">標(biāo)題</td>
<td width="5%">標(biāo)題</td>
<td width="5%">標(biāo)題</td>
</tr>
<tr class="table-tr-content">
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
</tr>
<tr class="table-tr-content">
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
</tr>
<tr class="table-tr-content">
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
</tr>
<tr class="table-tr-content">
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
</tr>
<tr class="table-tr-content">
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
</tr>
<tr class="table-tr-content">
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
</tr>
<tr class="table-tr-content">
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
</tr>
<tr class="table-tr-content">
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
</tr>
<tr class="table-tr-content">
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
</tr>
<tr class="table-tr-content">
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
</tr>
<tr class="table-tr-content">
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
</tr>
<tr class="table-tr-content">
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
</tr>
</body>
</html>
js代碼:
<script type="text/javascript" src="jquery-1.6.4.js"></script>
<script>
$(function(){
///////datagrid選中行變色與鼠標(biāo)經(jīng)過行變色///////////////
var dtSelector = ".list";
var tbList = $(dtSelector);
tbList.each(function() {
var self = this;
$("tr:even:not(:first)", $(self)).addClass("normalEvenTD"); // 從標(biāo)頭行下一行開始的奇數(shù)行,行數(shù):(1,3,5...)
$("tr:odd", $(self)).addClass("normalOddTD"); // 從標(biāo)頭行下一行開始的偶數(shù)行,行數(shù):(2,4,6...)
// 鼠標(biāo)經(jīng)過的行變色
$("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>
效果顯示:
復(fù)制代碼 代碼如下:
<html>
<head>
<style type="text/css">
.table-tr-title{
height: 26px;
font-size: 12px;
text-align: center;
}
.table-tr-content{
height: 18px;
background: #FFFFFF;
text-align: center;
font-size: 12px;
}
.normalEvenTD{
background: #DFD8D8;
}
.normalOddTD{
background: #FFFFFF;
}
.hoverTD{
background-color: #eafcd5;
height: 18px;
text-align: center;
font-size: 12px;
}
.trSelected{
background-color: #51b2f6;
height: 18px;
text-align: center;
font-size: 12px;
}
</style>
</head>
<body>
<table width="99%" class="list" style="word-break: break-all" border="0"
align="center" cellpadding="0" cellspacing="1" bgcolor="#c0de98">
<tr class="table-tr-title">
<td width="5%">標(biāo)題</td>
<td width="5%">標(biāo)題</td>
<td width="5%">標(biāo)題</td>
<td width="5%">標(biāo)題</td>
</tr>
<tr class="table-tr-content">
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
</tr>
<tr class="table-tr-content">
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
</tr>
<tr class="table-tr-content">
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
</tr>
<tr class="table-tr-content">
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
</tr>
<tr class="table-tr-content">
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
</tr>
<tr class="table-tr-content">
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
</tr>
<tr class="table-tr-content">
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
</tr>
<tr class="table-tr-content">
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
</tr>
<tr class="table-tr-content">
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
</tr>
<tr class="table-tr-content">
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
</tr>
<tr class="table-tr-content">
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
</tr>
<tr class="table-tr-content">
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
<td width="5%">數(shù)據(jù)</td>
</tr>
</body>
</html>
js代碼:
復(fù)制代碼 代碼如下:
<script type="text/javascript" src="jquery-1.6.4.js"></script>
<script>
$(function(){
///////datagrid選中行變色與鼠標(biāo)經(jīng)過行變色///////////////
var dtSelector = ".list";
var tbList = $(dtSelector);
tbList.each(function() {
var self = this;
$("tr:even:not(:first)", $(self)).addClass("normalEvenTD"); // 從標(biāo)頭行下一行開始的奇數(shù)行,行數(shù):(1,3,5...)
$("tr:odd", $(self)).addClass("normalOddTD"); // 從標(biāo)頭行下一行開始的偶數(shù)行,行數(shù):(2,4,6...)
// 鼠標(biāo)經(jīng)過的行變色
$("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>
效果顯示:

相關(guān)文章
jquery easyui中treegrid用法的簡單實(shí)例
本篇文章主要是對jquery easyui中treegrid用法的簡單實(shí)例進(jìn)行了介紹,需要的朋友可以過來參考下,希望對大家有所幫助2014-02-02jQuery EasyUI Layout實(shí)現(xiàn)tabs標(biāo)簽的實(shí)例
這篇文章主要介紹了jQuery EasyUI Layout實(shí)現(xiàn)tabs標(biāo)簽的實(shí)例的相關(guān)資料,希望通過本文能幫助到大家實(shí)現(xiàn)這樣的功能,需要的朋友可以參考下2017-09-09基于jQuery架構(gòu)javascript基礎(chǔ)體系
jQuery畢竟還只是一個(gè)基礎(chǔ)的最底層的工具集,封裝元素選擇器,事件等等,基本上能滿足一般的需求,但要從整體的WEB的周度來看,為了提高javascript開發(fā)的效率與可重用性,就需要有一個(gè)整體的布局2011-01-01JQuery 給元素綁定click事件多次執(zhí)行的解決方法
這篇文章主要介紹了JQuery 給元素綁定click事件多次執(zhí)行的解決方法,比較實(shí)用,需要的朋友可以參考下2014-09-09jQuery實(shí)現(xiàn)文件上傳進(jìn)度條特效
帶進(jìn)度條的文件上傳特效,每個(gè)文件都有進(jìn)度條,都有上傳詳情介紹。效果非常不錯(cuò),這里推薦給大家。2015-08-08