Jquery 实现表格颜色交替变化,点击选中行,鼠标移过颜色变化效果图如下:
源码(Demo)打包下载
html代码如下:
复制代码 代码如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="/UploadFiles/2021-04-02/jquery.min.js"><script type="text/javascript" src="/UploadFiles/2021-04-02/table-row-1.0.js"><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%">标题</td>
<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>
<td width="5%">数据</td>
</tr>
<tr class="table-tr-content">
<td width="5%">数据</td>
<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>
<td width="5%">数据</td>
</tr>
<tr class="table-tr-content">
<td width="5%">数据</td>
<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>
<td width="5%">数据</td>
</tr>
<tr class="table-tr-content">
<td width="5%">数据</td>
<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>
<td width="5%">数据</td>
</tr>
<tr class="table-tr-content">
<td width="5%">数据</td>
<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>
<td width="5%">数据</td>
</tr>
<tr class="table-tr-content">
<td width="5%">数据</td>
<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>
<td width="5%">数据</td>
</tr>
<tr class="table-tr-content">
<td width="5%">数据</td>
<td width="5%">数据</td>
<td width="5%">数据</td>
<td width="5%">数据</td>
</tr>
</body>
</html>
table-row-1.0.js
复制代码 代码如下:
$(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');
});
});
});
源码(Demo)打包下载
html代码如下:
复制代码 代码如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="/UploadFiles/2021-04-02/jquery.min.js"><script type="text/javascript" src="/UploadFiles/2021-04-02/table-row-1.0.js"><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%">标题</td>
<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>
<td width="5%">数据</td>
</tr>
<tr class="table-tr-content">
<td width="5%">数据</td>
<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>
<td width="5%">数据</td>
</tr>
<tr class="table-tr-content">
<td width="5%">数据</td>
<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>
<td width="5%">数据</td>
</tr>
<tr class="table-tr-content">
<td width="5%">数据</td>
<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>
<td width="5%">数据</td>
</tr>
<tr class="table-tr-content">
<td width="5%">数据</td>
<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>
<td width="5%">数据</td>
</tr>
<tr class="table-tr-content">
<td width="5%">数据</td>
<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>
<td width="5%">数据</td>
</tr>
<tr class="table-tr-content">
<td width="5%">数据</td>
<td width="5%">数据</td>
<td width="5%">数据</td>
<td width="5%">数据</td>
</tr>
</body>
</html>
table-row-1.0.js
复制代码 代码如下:
$(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');
});
});
});
标签:
表格颜色,交替变化
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com
暂无“Jquery 实现表格颜色交替变化鼠标移过颜色变化实例”评论...