CheckBoxList中如何让鼠标选中的对象改变背景颜色,说明白点就是鼠标单击哪个item,把这个item的背景色给变一下,不是checkbox选中的对象变颜色,哪位朋友帮忙指导一下

解决方案 »

  1.   

    根据鼠标事件的(e)来找到当前item 改之
      

  2.   

    mousehover 事件,根据sender试试判断出是哪个item,或者用数组记录下item的坐标进行判断,手头没工具,只能这么说了。
      

  3.   

    ChickListBox,鼠标选择的项好像本来和别的就不一样。
    如果想要选中的项颜色不同估计要自己重写控件中绘制Item的函数了。
      

  4.   

    即使不考虑改变颜色,我现在对于怎么判断鼠标点击了哪个item也是一头雾水
      

  5.   

    <asp:CheckBoxList ID="CheckBoxList1" runat="server">
            <asp:ListItem Text="呵呵" Value="0" onclick="if(this.checked)this.parentNode.childNodes[1].style.backgroundColor='red';else this.parentNode.childNodes[1].style.backgroundColor='';"></asp:ListItem>
            <asp:ListItem Text="哈哈" Value="1" onclick="if(this.checked)this.parentNode.childNodes[1].style.backgroundColor='red';else this.parentNode.childNodes[1].style.backgroundColor='';"></asp:ListItem>
            </asp:CheckBoxList>
      

  6.   

    为什么这么写不好用呢
    <asp:CheckBoxList ID="CheckBoxList1" runat="server" 
                                                DataSourceID="SqlDataSource1" DataTextField="name" DataValueField="name" OnSelectedIndexChanged="Check_Clicked"
                                                AutoPostBack="True" BackColor="AntiqueWhite" BorderStyle="Ridge"                                            >
                                                <asp:ListItem Selected="True" onclick="if(this.checked)this.parentNode.childNodes[1].style.backgroundColor='red';else this.parentNode.childNodes[1].style.backgroundColor='';"></asp:ListItem>
                                            
                                            </asp:CheckBoxList> 
      

  7.   

    谢谢wzy_love_sly的回答,代码没问题,可是我问的并不是让checked的对象变色,而是让鼠标点的某一对象变色,
    就是鼠标点哪个对象,哪个对象变背景颜色