我们如何在鼠标悬停事件上更改光标,asp.net按钮的背景颜色 [英] how we change cursor,backcolor of asp.net button on mouse over event

查看:187
本文介绍了我们如何在鼠标悬停事件上更改光标,asp.net按钮的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆