這主要是透過 javascript 來讓滑鼠游標存在的 Row 變顏色
原始碼如下 (參考Change table row background colour on mouse over-move using JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
<html> <head> <title>Change table row background colour on mouse over-move using JavaScript</title> </head> <body> <table align="center" id="tblMain" style="border: solid 1px black;" cellpadding="0" cellspacing="0" width="200px"> <th>Heading</th> <tr><td>Row 1</td></tr> <tr><td>Row 1</td></tr> <tr><td>Row 2</td></tr> <tr><td>Row 3</td></tr> <tr><td>Row 4</td></tr> <tr><td>Row 5</td></tr> <tr><td>Row 6</td></tr> </table> <script language="javascript"> var tbl = document.getElementById("tblMain"); if (tbl != null) { if (tbl.rows[0] != null) { tbl.rows[0].style.backgroundColor = "#365890"; tbl.rows[0].style.color = "#FFFFFF"; } //這邊從第i=1開始,亦即避開標題列 for (var i = 1; i < tbl.rows.length; i++) { tbl.rows[i].style.cursor = "pointer"; tbl.rows[i].onmousemove = function () { this.style.backgroundColor = "#FF2080"; this.style.color = "#FFFFFF"; }; tbl.rows[i].onmouseout = function () { this.style.backgroundColor = ""; this.style.color = ""; }; } } </script> </body> </html> |