<!DOCTYPE html>
<html>
<head>
<title> new document </title>
<meta http-equiv="Content-Type" content="text/html; charset=gbk"/>
<script type="text/javascript">
window.onload = function(){
// 鼠标移动改变背景,可以通过给每行绑定鼠标移上事件和鼠标移除事件来改变所在行背景色。
var trs = document.getElementsByTagName("tr");
for(var tr of trs){
tr.onmouseover = function(){
this.style.backgroundColor = "#f2f2f2";
}
tr.onmouseout = function(){
this.style.backgroundColor = "#fff";
}
}
}
</script>
</head>
<body>
<table border="1" width="50%" id="table">
<tr>
<th>学号</th>
<th>姓名</th>
<th>操作</th>
</tr>
<tr>
<td>xh001</td>
<td>王小明</td>
</tr>
<tr>
<td>xh002</td>
<td>刘小芳</td>
</tr>
</table>
</body>
</html>
html table标签鼠标移进移出背景变色
最新推荐文章于 2024-02-28 10:42:02 发布