一直想实现onmouseover和onmouseout应用于RadioButtonList或CheckBoxList控件上,今晚终于有时间实现它。此功能就是当鼠标经过时RadioButtonList或CheckBoxList每一个ITem时,让Item有特效显示,离开时,恢复原样。可以看到效果:
using
System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// Summary description for FivePhases
/// </summary>
p
ublic class FivePhases
{
PRivate int _ID;
private string _N
ame;
public int ID
{
get { return _ID; }
set { _ID = value; }
}
public string Name
{
get { return _Name; }
set { _Name = value; }
}
public FivePhases()
{
//
// TODO: Add constructor
LOGic here
//
}
public FivePhases(int id, string name)
{
this.ID = id;
this._Name = name;
}
}
<asp:CheckBoxList ID="RadioButtonListFivePhases" runat="server" Re
PEatDirection="Horizontal"></asp:CheckBoxList>
using System.Data.OleDb;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Insus.NET;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, Event
args e)
{
if (!IsPostBack)
Data_Binding();
}
private void Data_Binding()
{
this.RadioButtonListFivePhases.DataSource = GetFivePhases();
this.RadioButtonListFivePhases.DataTextField = "Name";
this.RadioButtonListFivePhases.DataVal
UEFIeld = "ID";
this.RadioButtonListFivePhases.DataBind();
}
}
<script type="text/javascript">
function windowOnLoad() {
VAR rbl = document.getElementById('<%= RadioButtonListFivePhases.ClientID %>');
var labels = rbl.
getelementsbytagname('label');
for (var i = 0; i < labels.length;
i++) {
var lbl = labels[i];
lbl.onmouseover = function () {
this.
classname = 'overStyle';
};
lbl.onmouseout = function () {
this.className = 'outStyle';
};
}
}
window.onload = windowOnLoad;
</script>