国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

實現onmouseover和onmouseout應用于RadioButtonList或CheckBoxList控件上

2024-07-10 13:17:54
字體:
來源:轉載
供稿:網友

一直想實現onmouseover和onmouseout應用于RadioButtonList或CheckBoxList控件上,今晚終于有時間實現它。此功能就是當鼠標經過時RadioButtonList或CheckBoxList每一個Item時,讓Item有特效顯示,離開時,恢復原樣。可以看到效果:

RadioButtonList效果:

實現onmouseover和onmouseout應用于RadioButtonList或CheckBoxList控件上


CheckBoxList效果:

實現onmouseover和onmouseout應用于RadioButtonList或CheckBoxList控件上

 

這資實現數據,Insus.NET準備了五行(Five Phases)

實現onmouseover和onmouseout應用于RadioButtonList或CheckBoxList控件上

 

創建一個對象[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 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>

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 平舆县| 南部县| 抚顺市| 合肥市| 伊春市| 即墨市| 兴城市| 惠州市| 酒泉市| 吉安县| 越西县| 龙岩市| 紫阳县| 甘德县| 常州市| 大悟县| 揭东县| 正定县| 兴义市| 肇源县| 安平县| 宜兰市| 新乡市| 额济纳旗| 准格尔旗| 安图县| 龙游县| 太和县| 凤庆县| 周宁县| 来凤县| 五家渠市| 金山区| 海安县| 奉贤区| 永宁县| 德兴市| 普兰县| 沭阳县| 漯河市| 六枝特区|