将鼠标悬停在aspxbutton上时如何更改其背景色 [英] How to change the backcolour of aspxbutton when mouseover on it
本文介绍了将鼠标悬停在aspxbutton上时如何更改其背景色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
有没有人可以帮助我,将鼠标悬停在aspxbutton上时如何更改其背景色?
REgards
Haluk
Hello guys,
Is there anyone who can help me about how to change the backcolour of aspxbutton when mouseover on it?
REgards
Haluk
推荐答案
您可以通过CSS进行操作:
You can do it via CSS:
.button
{
background-color: Blue; /*This is your regular color*/
}
.button:hover
{
background-color: Yellow; /*The color when you pass mouser over it*/
}
在您的HTML中:
In your HTML:
<asp:button id="button1" runat="server" cssclass="button" text="Click Me!" xmlns:asp="#unknown" />
或为您的asp.net页面实现外观=)
希望对您有所帮助.
Or implement a skin for your asp.net page =)
Hope it helps.
这是我的按钮的aspx代码
This is my aspx code for button
<asp:button runat="server" id="btn1" text="Click Me" xmlns:asp="#unknown" />
在我的样式表中,我要添加2种样式.一个用于静态,另一个用于鼠标悬停.
In my style sheet i am adding 2 styles. one for static and other for mouse hover.
.hoverbutton
{color:Navy;
background-color:Navy;
}
.static
{color:White;
background-color:White;
}
并在aspx.cs的page_load中
And in page_load of aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
btn1.Attributes.Add("class", "static");
btn1.Attributes.Add("onMouseOver", "this.className='hooverbutton'");
btn1.Attributes.Add("onMouseOut", "this.className='static'");
}
为onmouseover
和onmouseout
创建两个javascript函数:
Hi,
Create two javascript functions foronmouseover
andonmouseout
:
function OnHover(val) {
val.style.backgroundColor = "red";
}
function OnOut(val) {
val.style.backgroundColor = "";
}
并在您的HTML中调用以下函数:
And call these functions in your HTML:
<asp:button id="btn" runat="server" onmouseover="OnHover(this);" onmouseout="OnOut(this);" text="Test" />
--Amit
--Amit
这篇关于将鼠标悬停在aspxbutton上时如何更改其背景色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文