Home  >  Article  >  Web Front-end  >  Example of table rows changing color as the mouse moves_jquery

Example of table rows changing color as the mouse moves_jquery

WBOY
WBOYOriginal
2016-05-16 16:49:311182browse

1、设计表格

复制代码 代码如下:






































































工号 姓名 年龄 性别
2014010101 张峰 56
2014010102 李玉 42
2014010103 王珂 36
2014010104 张钰 31
2014010105 朱顾 44
2014010106 胡雨 35
2014010107 刘希 30
2014010108 孙宇 45
2014010109 谷雨 33
2014010110 科宇 45




2、设计样式
复制代码 代码如下:

.html_body .body_div{
width: 1340;
height: 595;
}
.body_div{
font-size: 12px;
background-color: #CCCCCC;
}
.tr_odd{
background-color: orange;
}
.tr_even{
background-color: aqua;
}
.mouse_color{
background-color: green;
}
#tab{
border: 1px #FF0000 solid;
text-align: center;
width: 100%;
height: 100%;
}

3、设计JS
复制代码 代码如下:

//设置奇数行背景色
$("#tab tr:odd").find("td").addClass("tr_odd");
//设置偶数行背景色
$("#tab tr:even").find("td").addClass("tr_even");

/**
* Color of mouse moved to
*/
$("#tab tr").mouseover(function(){
$(this).find("td").addClass("mouse_color");
});

/**
* Color of mouse move
*/
$("#tab tr").mouseout(function(){
$(this).find("td").removeClass("mouse_color");
});

4. Design results

(1) Initialization
Example of table rows changing color as the mouse moves_jquery
(2) Click on the odd row
Example of table rows changing color as the mouse moves_jquery
(3) Click on the even row
Example of table rows changing color as the mouse moves_jquery
5. Appendix
Copy code The code is as follows:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>





table随鼠标变色

















































































工号 姓名 年龄 性别
2014010101 张峰 56
2014010102 李玉 42
2014010103 王珂 36
2014010104 张钰 31
2014010105 朱顾 44
2014010106 胡雨 35
2014010107 刘希 30
2014010108 孙宇 45
2014010109 谷雨 33
2014010110 科宇 45




Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn