日期:2014-05-18  浏览次数:20454 次

repeater 能实现隔行换色,也能实现鼠标悬停效果,但我想同时实现,单击某行,就让这一行处于被选 中状态,整行变为红色。

repeater 能实现隔行换色,也能实现鼠标悬停效果,但我想同时实现,单击某行,就让这一行处于被选 中状态,整行变为红色。

请看我实现的一部分功能,我只能实现隔行换色和 鼠标悬停效果。

C# code


<asp:Repeater ID="Repeater1" OnItemDataBound="Repeater1_ItemDataBound" runat="server">
                <HeaderTemplate>
                <tr bgcolor="#add8e6">
                    <td height="25" class="tabletitle" align="center">ID</td>
                    <td class="tabletitle"  align="center">状态</td>
                    <td class="tabletitle"  align="center">消缺序号</td>
                    <td class="tabletitle"  align="center">发现时间</td>
                  </tr>
                </HeaderTemplate>
                <ItemTemplate>
                <tr bgcolor="#e6e6fa" style="cursor:hand"  onmouseover="javascript:this.style.backgroundColor='#FFCC33';"    onmouseout="javascript:this.style.backgroundColor='#e6e6fa';" ondblclick="openChild(this,<%#Eval("ID")%>,5)">
                    <td height="25" align="center"><%#Eval("ID")%></td>
                    <td><%#CheckState(Convert.ToString(Eval("StateNow")))%> </td>
                    <td><%#Eval("FlowOrder")%></td>
                    <td><%#Eval("FindDate")%></td>
                   </tr>
                </ItemTemplate>
                <AlternatingItemTemplate>
                <tr bgcolor="#f5f5dc" style="cursor:hand"  onmouseover="javascript:this.style.backgroundColor='#FFCC33';"    onmouseout="javascript:this.style.backgroundColor='#f5f5dc';" ondblclick="openChild(this,<%#Eval("ID")%>,5)">
                    <td height="25" align="center"><%#Eval("ID")%></td>
                    <td><%#CheckState(Convert.ToString(Eval("StateNow")))%> </td>
                    <td><%#Eval("FlowOrder")%></td>
                    <td><%#Eval("FindDate")%></td>
                    </tr>
                </AlternatingItemTemplate>
            </asp:Repeater>






我的方法很简单,因为是 repeater ,所以我用了 ItemTemplate 和
 AlternatingItemTemplate
 
在 ItemTemplate 里的行
<tr bgcolor="#e6e6fa" style="cursor:hand" onmouseover="javascript:this.style.backgroundColor='#FFCC33';" onmouseout="javascript:this.style.backgroundColor='#e6e6fa';" ondblclick="openChild(this,<%#Eval("ID")%>,5)">

首先为整行加一背景色 bgcolor="#e6e6fa" ,然后,用onmouseover 实现鼠标效果 用 onmouseout 实现鼠标移开后,恢复这行原来的背景色

,同理 在AlternatingItemTemplate 模板里也是这样实现。


现在就是不知道怎么才能实现 单击某行,就让这一行处于被选 中状态,整行变为红色。
然后,如果单击其它行,则让其它行处于被选 中状态,整行变为红色,让刚才那行恢复原来行的背景色。。




请各位高人帮帮忙!!万分感谢!!


------解决方案--------------------
晕 改需求了
table中加ID t为this

function click(t)//点击
{
var tab=document.getElementById('tableID').getElementsByTagName('td');
for(var j=0;j<tab.length;j++)
{
tab[j].backgroundColor='';/取消全部td背景
}/
var td=t.getElementsByTagName('td');
for(var i=0;i<td.length;i++)
{
td[i].backgroundColor='red';//设置选中行中的td背景
}
}
------解决方案--------------------