读书人

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

发布时间: 2013-07-20 11:07:48 作者: rapoo

给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

读书人网 >C#

热点推荐