鼠标事件更改linkbutton的backgroundimage [英] mouse event change the backgroundimage of linkbutton

查看:108
本文介绍了鼠标事件更改linkbutton的backgroundimage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码:

the code below:

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







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


-------------------------------------------------- ---------------------
我使用功能mouseevent()方法的代码之一,只能显示颜色,但不能显示图像.我不知道为什么.请帮我!


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

推荐答案

解决此问题的最佳方法是使用CSS.
在CSS类内,您可以指定background属性,它将背景图像用作背景,或者,如果图像不存在,则将使用背景色.示例:
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>



然后,您必须将此类分配给链接按钮.
尝试以下js代码,尽管我不确定:



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";



我宁愿使用JQuery处理所有javascript.

那么它看起来像:



I would rather use JQuery to handle all javascript.

then it would look like:


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


这是因为您只能为任何控件指定一件事
背景图片或背景色.
1)创建具有所需背景色的图像,然后分配该图像.
2)或在按钮周围创建一个div标签,然后为该div标签提供背景色,然后为按钮控件分配一个透明图像.
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.


这篇关于鼠标事件更改linkbutton的backgroundimage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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