开发者

Changing background image to a button

I am trying to change the backgound-image of a button but it doesn't work as I thought !! the CSS is OK and it is as follows :

#ITA
{
    float: right;
    margin: 5px 85px;
    width: 40px;
    height: 40px;
    background: #FFFFFF url("../ITA_off.png") center center no-repeat;
    border:开发者_开发知识库 0;
}

my javascript function in the "HEAD" is

function cambiaBandiera() {
    test=document.getElementById("ITA");
    test.backgroundimage="ITA_on.png";
}

and the button is as follows

<input type="button" id="ITA" onClick="cambiaBandiera()" />

What's wrong ?

Please HELP !

Thanx in advance

Alex


test.style.backgroundImage = "url(foo.png)"


The i in backgroundimage should be capital eg backgroundImage, try this:

function cambiaBandiera() {
 test=document.getElementById("ITA");
 test.backgroundImage="url(ITA_on.png)";
}

You are trying to change the background-image but - is special character in javascript, for this reason, it should be stripped and first letter of ending word should be capitalized.

Make sure that you have an element with id ITA on your page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜