首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

给asp:Button加上背景解决方法

2013-07-20 
给asp:Button加上背景做了个选项卡,放了四个按钮,然后分别用了四个Css样式如:style typetext/css.aLi

给asp:Button加上背景
做了个选项卡,放了四个按钮,然后分别用了四个Css样式
如:
<style type="text/css">
.aLink1 
{
background-image:url(Images/tab_01.gif);
width:73px;
height:27px;
cursor:pointer;
}
//-----这是第一个Button的样式,其它的类似就不写出来了
</style>
<asp:Button ID="Button1" runat="server" Text="" class="aLink1" BorderWidth="0" />
现在我想实现点击第一个Button1的时候,让它的背景图片变成另外一张,而点击第二个Button时,第一个Button变回aLink1的样式,第二个Button的图片变成另外一张,以此类推。


[解决办法]

<asp:Button ID="Button2" runat="server"  OnClientClick="changeBg(this);return false;" Text="backgroundImage" BorderWidth="0" />
<asp:Button ID="Button1" runat="server"  OnClientClick="changeBg(this);return false;" Text="backgroundImage" BorderWidth="0" />

 function changeBg(active) {
//先将所有bttton重置为初始
        document.getElementById("Button2").style.backgroundImage = '';
        document.getElementById("Button1").style.backgroundImage = '';
        active.style.backgroundImage = 'url(fin_bg2.png)';
    }

[解决办法]
思路跟楼上差不多,设置几个样式,然后用JQ互换样式
[解决办法]
引用:
Quote: 引用:

Quote:

试了试效果,结果点击以后成为空背景了,不知道是什么地方出错了。求帮助

代码贴上来
[解决办法]
引用:
<asp:Button ID="Button2" runat="server"  OnClientClick="changeBg(this);return false;" Text="backgroundImage" BorderWidth="0" />
<asp:Button ID="Button1" runat="server"  OnClientClick="changeBg(this);return false;" Text="backgroundImage" BorderWidth="0" />

 function changeBg(active) { 


//先将所有bttton重置为初始
        document.getElementById("Button2").style.backgroundImage = '';
        document.getElementById("Button1").style.backgroundImage = '';
        active.style.backgroundImage = 'url(fin_bg2.png)';
    }



+1

热点排行