读书人

onMouseOver对象有关问题

发布时间: 2012-02-09 18:22:27 作者: rapoo

onMouseOver对象问题
想问一下,如何用onMouseOver事件来做一下表格里面单行变色呢??

[解决办法]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN ">
<html>
<head>
<title> New Document </title>
<meta name= "Generator " content= "EditPlus ">
<meta name= "Author " content= " ">
<meta name= "Keywords " content= " ">
<meta name= "Description " content= " ">
</head>

<body>

<table width=100% style= "border-collapse:collapse; table-layout:fixed " border >
<tr onmouseover= "this.style.background= '#DDDDDD ' " onmouseout= "this.style.background= 'blue ' ">
<td width=20% >   </td> <td>   </td>
</tr>
<tr onmouseover= "this.style.background= '#DDDDDD ' " onmouseout= "this.style.background= 'blue ' ">
<td width=20%>   </td> <td>   </td>
</tr>
<tr onmouseover= "this.style.background= '#DDDDDD ' " onmouseout= "this.style.background= 'blue ' ">
<td width=20%>   </td> <td>   </td>
</tr>
<tr onmouseover= "this.style.background= '#DDDDDD ' " onmouseout= "this.style.background= 'blue ' ">
<td width=20%>   </td> <td>   </td>
</tr>
<tr onmouseover= "this.style.background= '#DDDDDD ' " onmouseout= "this.style.background= 'blue ' ">
<td width=20%>   </td> <td>   </td>
</tr>
<tr>
<td width=20%>   </td> <td>   </td>
</tr>
</table>
</body>
</html>

[解决办法]
自己分别给onmouseover\onmouseout写一个方法,参数就是tr的实例,
function mouseover(obj)
{
obj.bgcolor=red;
}
使用时
<tr onmouseover= "mouseover( '#DDDDDD '); " >
<td width=20%>   </td> <td>   </td>
</tr>
这样就好一些,注意代码的简单化

读书人网 >JavaScript

热点推荐