实现onmouseover和onmouseout应用于RadioButtonList或CheckBoxList控件上

发布时间:2022-04-16 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了实现onmouseover和onmouseout应用于RadioButtonList或CheckBoxList控件上脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

一直想实现onmouseover和onmouseout应用于RadioButtonList或CheckBoxList控件上,今晚终于有时间实现它。此功能就是当鼠标经过时RadioButtonList或CheckBoxList每一个ITem时,让Item有特效显示,离开时,恢复原样。可以看到效果:

RadioButtonList效果:


CheckBoxList效果:

 

这资实现数据,Insus.NET准备了五行(Five Phases)

 

创建一个对象[Five Phases]:
FivePhases.cs

复制代码 代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for FivePhases
/// </summary>
public class FivePhases
{
PRivate int _ID;
private string _Name;

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;
}
}

复制代码 代码如下:

private List<FivePhases> GetFivePhases()
{
List<FivePhases> ListFH = new List<FivePhases>();
FivePhases fh = new FivePhases();
fh.ID = 1;
fh.Name = "木";
ListFH.Add(fh);

fh = new FivePhases();
fh.ID = 2;
fh.Name = "火";
ListFH.Add(fh);

fh = new FivePhases();
fh.ID = 3;
fh.Name = "土";
ListFH.Add(fh);

fh = new FivePhases();
fh.ID = 4;
fh.Name = "金";
ListFH.Add(fh);

fh = new FivePhases();
fh.ID = 5;
fh.Name = "水";
ListFH.Add(fh);

return ListFH;
}

此时,你可以拉一个RadioButtonList或是CheckBoxList控件至网页中,此例以RadioButtonList控件为例
复制代码 代码如下:

<asp:CheckBoxList ID="RadioButtonListFivePhases" runat="server" RePEatDirection="Horizontal"></asp:CheckBoxList>

然后在cs绑定数据:
复制代码 代码如下:

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, Eventargs e)
{
if (!IsPostBack)
Data_Binding();
}

private void Data_Binding()
{
this.RadioButtonListFivePhases.DataSource = GetFivePhases();
this.RadioButtonListFivePhases.DataTextField = "Name";
this.RadioButtonListFivePhases.DataValUEFIeld = "ID";
this.RadioButtonListFivePhases.DataBind();
}

}

还得准备鼠标的over与out样式:
复制代码 代码如下:

<style type="text/css">
.overStyle {
font-weight: bold;
color: #f00;
}

.outStyle {
font-weight: normal;
color: none;
}
</style>

在Javascript中实现每个Item有onmouseover和onmouseout事件,因此还得写Javascript脚本,放于<head>内。
复制代码 代码如下:

<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>

脚本宝典总结

以上是脚本宝典为你收集整理的实现onmouseover和onmouseout应用于RadioButtonList或CheckBoxList控件上全部内容,希望文章能够帮你解决实现onmouseover和onmouseout应用于RadioButtonList或CheckBoxList控件上所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。