您的位置:首页 > 其它

在ImageButton上应用onmouseover和onmouseout事件

2008-10-23 21:52 337 查看
在.aspx文件中如下定义:

<html>
<head runat="server">
<title>Sigoway测试</title>
<script language="javascript">
//更改ImageButton的图片
function changeImageBtn(obj,src) //obj为ImageButton的ID,src为图片路径
{
document.getElementById(obj).src = src;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ImageButton id="imgBtn" runat="server"
AlternateText="Sigoway"
ImageUrl="图片路径"/>
</form>
</body>
</html>

在.cs文件中的Page_Load事件中如下定义:

protected void Page_Load(object sender, EventArgs e)
{
//imgBtn为页面中ImageButton控件的ID
//添加onmouseover事件
imgBtn.Attributes.Add("onmouseover", "JavaScript:changeImageBtn('imgBtn', '更改前图片路径')");
//添加onmouseout事件
imgBtn.Attributes.Add("onmouseout", "JavaScript:changeImageBtn('imgBtn', '更改后图片路径')");
}

这样就可以像HTML里img那样自由的应用js事件啦
通过这样的方式,你还可以自定义好多事件哦
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: