CSS+JS滑鼠移至上方儲存格變色

來源:互聯網
上載者:User

標籤:style   http   java   color   資料   io   for   cti   

  • 又一款滑鼠移至上方表格儲存格,表格變色的執行個體效果,運用了CSS和JS兩者技術的結合,因些相容性非常好,而且易於控制,代碼修改方便,跟表格讀取動態資料沒有任何關係,比較方便。

<html>
<head>
<title>滑鼠移至上方儲存格變色</title>
<meta http-equiv="content-Type" content="text/html;charset=gb2312">
<style type="text/css">
<!--
#myTable{
width:100%;border-collapse:collapse;margin:1em 0;
}
#myTable th,td{
text-align:left;padding:.5em;border:1px solid #fff;
}
th{
background-color:#328aa4;color:#fff;
}
td{background:#e5f1f4;}
tr.even td{background:#e5f1f4;}
tr.odd td{background:#f8fbfc;}
tr.over td{background:#bce774;}
tr.out td{}
-->
</style>
</head>
<body onload="changeTableBg();">
<table width="500" id="myTable" cellspacing="0" cellpadding="0">
<tr>
<th>title</th>
<th>title</th>
<th>title</th>
</tr>
<tr>
<td>Data</td>
<td>Data</td>
<td>Data</td>
</tr>
<tr>
<td>Data</td>
<td>Data</td>
<td>Data</td>
</tr>
</table>
<script type="text/javascript">
<!--
function changeTableBg()
{
var changeTr=document.getElementById("myTable").getElementsByTagName("tr");
for(i=0;i<changeTr.length;i++)
{
changeTr[i].className=(i%2>0)?"even":"odd";
changeTr[i].temp=changeTr[i].className;
changeTr[i].onmouseover=function(){
this.className=‘over‘;
}
changeTr[i].onmouseout=function(){
this.className=this.temp;
}
}
}
//-->
</script>
</body>
</html>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.