實(shí)現(xiàn)onmouseover和onmouseout應(yīng)用于RadioButtonList或CheckBoxList控件上
一直想實(shí)現(xiàn)onmouseover和onmouseout應(yīng)用于RadioButtonList或CheckBoxList控件上,今晚終于有時(shí)間實(shí)現(xiàn)它。此功能就是當(dāng)鼠標(biāo)經(jīng)過時(shí)RadioButtonList或CheckBoxList每一個(gè)Item時(shí),讓Item有特效顯示,離開時(shí),恢復(fù)原樣??梢钥吹叫Ч?/P>
RadioButtonList效果:
CheckBoxList效果:
這資實(shí)現(xiàn)數(shù)據(jù),Insus.NET準(zhǔn)備了五行(Five Phases)
創(chuàng)建一個(gè)對(duì)象[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;
}
此時(shí),你可以拉一個(gè)RadioButtonList或是CheckBoxList控件至網(wǎng)頁中,此例以RadioButtonList控件為例。
<asp:CheckBoxList ID="RadioButtonListFivePhases" runat="server" RepeatDirection="Horizontal"></asp:CheckBoxList>
然后在cs綁定數(shù)據(jù):
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();
}
}
還得準(zhǔn)備鼠標(biāo)的over與out樣式:
<style type="text/css">
.overStyle {
font-weight: bold;
color: #f00;
}
.outStyle {
font-weight: normal;
color: none;
}
</style>
在Javascript中實(shí)現(xiàn)每個(gè)Item有onmouseover和onmouseout事件,因此還得寫Javascript腳本,放于<head>內(nèi)。
<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>
- 兼容ie和firefox的鼠標(biāo)經(jīng)過(onmouseover和onmouseout)實(shí)現(xiàn)--簡短版
- javascript mouseover、mouseout停止事件冒泡的解決方案
- js ondocumentready onmouseover onclick onmouseout 樣式
- onmouseover和onmouseout的一些問題思考
- 基于mouseout和mouseover等類似事件的冒泡問題解決方法
- 經(jīng)過綁定元素時(shí)會(huì)多次觸發(fā)mouseover和mouseout事件
- javascript中mouseover、mouseout使用詳解
相關(guān)文章
詳解.Net Core + Angular2 環(huán)境搭建
這篇文章主要介紹了詳解.Net Core + Angular2 環(huán)境搭建,具有一定的參考價(jià)值,有興趣的可以了解一下。2016-12-12asp.net 程序性能優(yōu)化的七個(gè)方面 (c#(或vb.net)程序改進(jìn))
在我們開發(fā)asp.net過程中,需要注意的一些細(xì)節(jié),以達(dá)到我們優(yōu)化程序執(zhí)行效率。2009-03-03ASP.NET向Javascript傳遞變量兩種實(shí)現(xiàn)方法
ASP.NET向Javascript傳遞變量兩種實(shí)現(xiàn)方法,需要的朋友可以參考下2012-12-12ASP.NET 5中使用AzureAD實(shí)現(xiàn)單點(diǎn)登錄
本文給大家介紹的是在ASP.NET 5中使用AzureAD實(shí)現(xiàn)單點(diǎn)登錄的方法和示例,有需要的小伙伴可以參考下。2015-07-07.NET Core/Framework如何創(chuàng)建委托大幅度提高反射調(diào)用的性能詳解
反射是一種很重要的技術(shù),下面這篇文章主要給大家介紹了關(guān)于.NET Core/Framework如何創(chuàng)建委托大幅度提高反射調(diào)用性能的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2018-09-09.Net Core+Angular Cli/Angular4開發(fā)環(huán)境搭建教程
這篇文章主要為大家詳細(xì)介紹了.Net Core+Angular Cli/Angular4開發(fā)環(huán)境搭建教程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06