<script type="text/javascript">
    //获取Repeater的每一行
    var oItems = document.getElementsByClassName("item");
    
    //循环为每一行绑定事件
    for (var i = 0; i < oItems.length; i++) {
        //鼠标悬浮时判断背景色
        oItems[i].onmouseover = function () {
            if (this.style.backgroundColor == "white")
                this.style.backgroundColor = "yellow";
        };
        
        //鼠标移除时判断背景色
        oItems[i].onmouseout = function () {
            if (this.style.backgroundColor == "yellow") {
                this.style.backgroundColor = "white";
            }
        };

        //点击时事件
        oItems[i].onclick = function () {
            //将所有行背景色变为白色
            for (var j = 0; j < oItems.length; j++) {
                oItems[j].style.backgroundColor = "white";
            }
            //将点击的行背景色变为红色
            this.style.backgroundColor = "red";
        };
    }
    
</script>

相关文章:

  • 2021-09-08
  • 2021-12-31
  • 2021-04-16
  • 2022-02-19
  • 2022-01-10
  • 2021-11-30
  • 2021-11-30
猜你喜欢
  • 2021-07-31
  • 2022-12-23
  • 2021-12-30
  • 2021-07-19
  • 2022-12-23
  • 2022-01-14
  • 2021-11-02
相关资源
相似解决方案