Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
the code below:

XML
<script type="text/jscript">
function mouseevent()
{
    document.getElementById("LinkButton1").style.backgroundImage="url('/images/4.gif')";
    document.getElementById("LinkButton1").style.backgroundColor="#345677";
}
</script>



XML
<div>
<asp:LinkButton ID="LinkButton1" Enabled="true" Text="测试背景图片" runat="server"></asp:LinkButton>

<button onmouseover="document.getElementById('LinkButton1').style.backgroundImage='url('/images/4.gif')';mouseevent();" title="sdf" value="dfian">
    dfsdfsdf</button>
</div>

-----------------------------------------------------------------------
I use one of code of function mouseevent() method ,only color can be show,but the image are not.I don't know why.help me,Please !
Posted
Comments
AngelLoose 10-Nov-10 2:48am    
by accident,I tried and soluted the problem.Share for all of you ,If you have a good please write here thanks!
document.getElementById("LinkButton").style.backgroundImage="url('../testers/images/1.jpg')"

The best way to solve this problem is to use CSS.
Inside the CSS class you can specify the background property which will take the image for a background or, if the image does not exist, it will use the background color instead. Example:
<style>
.myClass
{
    background:url(Images/top_banner/bck_top_banner.gif) repeat-x top #DDDDDD;
}
</style>


Then you have to assign this class to your link button.
Try this js code, though I am not sure about it:
document.getElementById("LinkButton1").attributes["class"]="myClass";


I would rather use JQuery to handle all javascript.

then it would look like:

$(".myClass").attr("class","myClass");
<pre />

good luck.
 
Share this answer
 
v3
Comments
AngelLoose 10-Nov-10 20:25pm    
thanks
It's because you can only specify only one thing to any control
either background image or background color.
1) either create image with background color you want and then assign that image.
2) or create a div tag around button, then give that div tag background color, and then assign a transparent image to button control.
 
Share this answer
 
Comments
AngelLoose 10-Nov-10 20:26pm    
thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900