<html> <head> <title> new document </title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <script type="text/javascript"> window.onload = function(){ // 鼠标移动改变背景,可以通过给每行绑定鼠标移上事件和鼠标移除事件来改变所在行背景色。 //获取每一行 var line = document.getElementsByTagName("tr"); for(var i = 0;i < line.length ;i++) { line[i].onmouseover = function() { // alert("测试下鼠标滑过这行有动静吗?"); line[i].style.backgroundColor = red; } line[i].onmouseout = function() { // alert("测试过鼠标滑出时候的动静"); line[i].style.backgroundColor = yellow; } } } // 编写一个函数,供添加按钮调用,动态在表格的最后一行添加子节点; function addLine(){ // alert("测试方法是否调用,果然还是管用的方法"); } // 创建删除函数 function remo(){ //获取所在行 //删除所在行 // alert("测试方法是否调用,果然还是管用的方法"); } </script> </head> <body> <table border="7" width="50%" id="table"> <tr> <th>学号</th> <th>姓名</th> <th>操作</th> </tr> <tr> <td>xh001</td> <td>王小明</td> <td><a href="javascript:remo();" >删除</a></td> <!--在删除按钮上添加点击事件 --> </tr> <tr> <td>xh002</td> <td>刘小芳</td> <td><a href="javascript:remo();" >删除</a></td> <!--在删除按钮上添加点击事件 --> </tr> </table> <input type="button" value="添加一行" onclick ="addLine()" /> <!--在添加按钮上添加点击事件 --> </body> </html>
问题:19行和24行的 颜色设置不成功.希望实现的是:当鼠标滑进每一行的时候该行背景颜色改变,滑出这一行的时候背景颜色也改变.
刚毅87
K丶L
bestDove
相关分类