在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事件啦
通过这样的方式,你还可以自定义好多事件哦
<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事件啦
通过这样的方式,你还可以自定义好多事件哦
相关文章推荐
- 在ImageButton上应用onmouseover和onmouseout事件
- javascript完美解决onMouseOver、onMouseOut冒泡事件方法简单
- js中onmouseover 和 onmouseout 事件
- [整理]css中如何写入onmouseover和onmouseout事件
- JQuery 之事件中的 ----- hover 与 onmouseover 、onmouseout 联系
- Table的onMouseOver和onMouseOut鼠标事件的问题
- onMouseOver|onMouseOut事件
- onMouseOver 和 onMouseOut事件冒泡
- js中常用的事件,onclick 单击事件、onblur 失去焦点事件、onchange改变事件、onmouseover鼠标进入事件、onmouseout鼠标移除事件、onsubmit提交事件
- CSS的onmouseover 和onmouseout事件
- onmouseover和onmouseout在Repeater控件中应用
- onmouseover和onmouseout在GridView中应用 Ver2
- js中常用的事件,onclick 单击事件、onblur 失去焦点事件、onchange改变事件、onmouseover鼠标进入事件、onmouseout鼠标移除事件、onsubmit提交事件
- onmouseover事件和onmouseout事件全面理解
- 解决子父级元素交替执行onmouseover、onmouseout事件干扰
- jQuery事件 鼠标移动效果 onmouseover方法与onmouseout方法
- Repeater控件添加onmouseover和onmouseout事件
- js常用事件总结及案例-onMouseOver、onMouseOut
- HTML onmouseover, onmouseout , onmousemove 事件属性
- onmouseover和onmouseout在GridView中应用