.net 中动态生成的表格,当鼠标经过tr时改变tr当前颜色,当鼠标移开恢复原来的颜色,高手们求教了!!!

解决方案 »

  1.   


        function changeColor(color) {
            var obj = document.getElementById(event.srcElement.id);
            obj.style.background = color;
        }
        <table id="Table_1">
        <tr id="TR_1" name="TR_1">
        <td id="TD_1" name="TD_1" onmouseover="changeColor('red')" onmouseout="changeColor('blue')">表格一</td>
        <td id="TD_2">表格二</td>
        </tr>
        </table>
      

  2.   

    表格是在后台动态生成的在html页面是没有表格的<table><tr><td></td></tr></table>这些属性的
      

  3.   

    JS 生成表格 ,你可以用 createElement 创建 然后在 body.Append()下
    C# 创建可以输出 字符串。然后 HTML 中用 <%# %> 的方式。至于变色的 用
    var oldColor = this.BackgroundColor;
    this.BackgroundColor = 颜色。this.BackgroundColor  =oldColor ;分别写在 onmouseover 和 onmouseout
      

  4.   

    jquery给table的tr设置mouseover和mouseout背景色
      

  5.   

    动态的也可以写mouseover和mouseout事件改变颜色  根据id写事件
      

  6.   


    $(document).ready(function () {                $("table tr").bind("mouseover", function () {
                $(this).css("background","#FF0000");
            });
            $("table tr").bind("mouseout", function () {
                $(this).css("background", "#FFFFFF");
            });    });table可换成你自己table的id标识!
      

  7.   

    +1
    table id="Table_1">
        <tr id="TR_1" name="TR_1" onmouseover="MouseIN(this)" onmouseout="MouseOut(this)">
        <td id="TD_1">表格一</td>
        <td id="TD_2">表格二</td>
        </tr>
        </table>
    <script>
    var oldColor;
    function MouseIN(Element) 
    {
            var oldColor= Element.style.background;
            Element.style.background = "red";
        }
    function MouseOut(Element)
    {
      Element.style.background = oldColor;

    </script>
      

  8.   

    参考:
    效果一:
    效果二:http://www.cnblogs.com/insus/archive/2012/10/29/2744769.html