1. 程式人生 > >HTML中實現滑鼠經停整行(tr)變色

HTML中實現滑鼠經停整行(tr)變色

在網頁製作的過程中有時候要實現那種在滑鼠經過一個表格的某一行的時候,要整行的背景顏色發生變化,以表明該行正中焦點,網上有一大堆這方面的程式碼,但是好多都還要加上一大堆得javascript程式碼,本人再次自己寫了個簡單實用的小程式碼

1.首先在</head>之前插入這麼一段程式碼

<style type="text/css">
tr.change:hover
{
background-color:#00FF00
}
</style>

然後再要變色的表格處的<tr>標籤處加入如下

<tr class="change">,就可以實現

奉上一個小例子的程式碼

<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=shift_jis" />
<title>change</title>
<style type="text/css">
tr.change:hover
{
background-color:#00FF00
}
</style>
</head>


<body>
<h1>滑鼠經停變色</h1>
<table width="80%" border="1" align="center">
  <tr class="change">
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr class="change">
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr class="change">
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
</body>
</html>