表格高亮顯示
阿新 • • 發佈:2018-11-27
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>表格高亮顯示</title> <script> function changeColor(id,flag){ if(flag=='over'){ document.getElementById(id).style.backgroundColor="red"; }else if(flag=='out'){ document.getElementById(id).style.backgroundColor=""; } }; </script> </head> <body> <table border="1" width="500" height="50" align="center" id="tbl"> <thead> <tr> <th>編號</th> <th>姓名</th> <th>年齡</th> </tr> </thead> <tbody> <tr id="tr1" onmouseover="changeColor('tr1','over')" onmouseout="changeColor('tr1','out')"> <td>1</td> <td>張三</td> <td>22</td> </tr> <tr id="tr2" onmouseover="changeColor('tr2','over')" onmouseout="changeColor('tr2','out')"> <td>2</td> <td>李四</td> <td>25</td> </tr> <tr id="tr3" onmouseover="changeColor('tr3','over')" onmouseout="changeColor('tr3','out')"> <td>3</td> <td>王五</td> <td>27</td> </tr> <tr id="tr4" onmouseover="changeColor('tr4','over')" onmouseout="changeColor('tr4','out')"> <td>4</td> <td>趙六</td> <td>29</td> </tr> <tr id="tr5" onmouseover="changeColor('tr5','over')" onmouseout="changeColor('tr5','out')"> <td>5</td> <td>田七</td> <td>30</td> </tr> <tr id="tr6" onmouseover="changeColor('tr6','over')" onmouseout="changeColor('tr6','out')"> <td>6</td> <td>汾九</td> <td>20</td> </tr> </tbody> </table> </body> </html>