Jquery方法

<head>
    <script src="jquery-1.4.1.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {

            // 不需要on——
            $(".table1 tr").mouseenter(function () {
                $(this).css("backgroundColor", "yellow");
            }).mouseleave(function () {
                $(this).css("backgroundColor", "white");
            });
        })
    </script>
</head>
<body>
    <table class="table1">
        <tr>
            <td>
                喜洋洋
            </td>
        </tr>
        <tr>
            <td>
                喜洋洋
            </td>
        </tr>
        <tr>
            <td>
                喜洋洋
            </td>
        </tr>
        <tr>
            <td>
                喜洋洋
            </td>
        </tr>
        <tr>
            <td>
                喜洋洋
            </td>
        </tr>
    </table>
</body>

 

Js方法

<head>
    <script type="text/javascript">
        function ChangeColor() {
            var table = document.getElementByIdx_x("table1");
            var trs = table.getElementsByTagName("tr");
            for (var i = 0; i < trs.length; i++) {
               

               // 事件前面有on——
                trs[i].onmouseenter = function () {
                    this.style.backgroundColor = "yellow";
                }
                trs[i].onmouseleave = function () {
                    this.style.backgroundColor = "white";
                }
            }
        }
    </script>
</head>

 

转自:http://blog.sina.com.cn/s/blog_67aaf4440100r79v.html

相关文章:

  • 2022-12-23
  • 2022-02-16
  • 2022-02-10
  • 2022-02-19
  • 2021-12-10
  • 2022-12-23
  • 2021-12-09
  • 2022-02-22
猜你喜欢
  • 2021-04-06
  • 2021-10-03
  • 2021-08-26
  • 2022-12-23
  • 2021-06-04
  • 2022-12-23
  • 2022-02-20
相关资源
相似解决方案