我们如何在鼠标悬停事件上更改光标,asp.net按钮的背景颜色 [英] how we change cursor,backcolor of asp.net button on mouse over event
问题描述
Button2.Attributes.Add(onmouseover,this.style.cursor ='wait');
Button2.Attributes.Add(onmouseover,this.style.backgroundColor ='#FF3399');
Button2.Attributes.Add(onmouseout,this.style.backgroundColor ='Black');
通过此代码只有颜色变化但光标没有变化
Button2.Attributes.Add("onmouseover", "this.style.cursor='wait'");
Button2.Attributes.Add("onmouseover", "this.style.backgroundColor='#FF3399'");
Button2.Attributes.Add("onmouseout", "this.style.backgroundColor='Black'");
By this code only color changes but cursor not changes
推荐答案
试试这个,
Try this,
Button2.Attributes.Add("onmouseover", "this.style.cursor=pointer");
// this.style.cursor=hand (try it as well, I'm not sure about it though)
相反,我更喜欢 CSS 。见下文,
Rather I'd prefer CSS over here. See below,
.btn
{
}
.btn : hover
{
cursor: pointer;
}
和 .aspx文件中的按钮
and your buttons in .aspx file
<asp:button id="Button2" runat="server" cssclass="btn" text="Click Me !!" xmlns:asp="#unknown" />
-KR
-KR
因为你的代码会覆盖其他2个属性测试。
使用CSS。
将以下代码添加到aspx或html页面。
Its because your code overwrites other 2 attributes.
Use CSS to do so.
Add the following code to you aspx or html page.
<style>
.btn :hover
{
cursor:wait;
backgroud-color:#ff3399;
color:black;
}
</style>
将此css课程添加到您的按钮
Add this css class to your button
Button2.Attributes.Add("class", "btn");
这篇关于我们如何在鼠标悬停事件上更改光标,asp.net按钮的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!