Home >Web Front-end >JS Tutorial >Table row mouse click highlighting effect code implemented by JS_javascript skills
The example in this article describes the code for the mouse click highlighting effect of table rows implemented in JS. Share it with everyone for your reference, the details are as follows:
Occasionally when I read the net worth announcement of Tiantian Fund Network, I found a piece of js code stripped from the source code. I feel it is more practical. I would like to share it (only valid for IE)
<script type="text/javascript"> var highlightcolor='#E0F2FE'; var clickcolor='#ffedd2'; function MouseOver(){ var source=event.srcElement; if (source.tagName=="TD"){ source=source.parentElement; var cells = source.children; if (cells[0].style.backgroundColor!=highlightcolor&&cells[0].style.backgroundColor!=clickcolor) for(i=0;i<cells.length;i++){ cells[i].style.backgroundColor=highlightcolor; } } } function MouseOut(){ var source=event.srcElement; if (source.tagName=="TD"){ source=source.parentElement; var cells = source.children; if (cells[0].style.backgroundColor!=clickcolor) for(i=0;i<cells.length;i++){ cells[i].style.backgroundColor=""; } } } function MouseClick(){ var source=event.srcElement; if (source.tagName=="TD"){ source=source.parentElement; var cells = source.children; if (cells[0].style.backgroundColor!=clickcolor) for(i=0;i<cells.length;i++) cells[i].style.backgroundColor=clickcolor; else for(i=0;i<cells.length;i++) cells[i].style.backgroundColor=""; } } </script> <table onmouseover="MouseOver()" onclick="MouseClick()" onmouseout="MouseOut()" cellspacing="0" bordercolordark="#ffffff" bordercolorlight="#cccccc" border="1" width="80%" align="center" style="cursor:pointer"> <tr> <td>1</td> <td>a</td> <td>b</td> </tr> <tr> <td>2</td> <td>c</td> <td>d</td> </tr> <tr> <td>3</td> <td>e</td> <td>f </td> </tr> <tr> <td>4</td> <td>g</td> <td>h </td> </tr> </table>
I hope this article will be helpful to everyone in JavaScript programming.