在onclick事件上更改按钮的背景图像

Alp*_*n67 0 html javascript css

为什么这不起作用?在Firebug中,当我点击按钮时,它总是告诉我cambiaBandiera没有定义...

救命

亚历克斯

CSS

#ITA{
float:right;
margin : 5px 85px;
width:40px;
height:40px;
background : #FFFFFF url("../ITA_off.png") center center no-repeat;
border:0;
}
Run Code Online (Sandbox Code Playgroud)

JAVASCRIPT(在HEAD中)

<style type="text/javascript">
function cambiaBandiera() {
test=document.getElementById("ITA");
test.style.backgroundImage="url('../ITA_on.png')";
}
</style>
Run Code Online (Sandbox Code Playgroud)

这是HTML

<div id="bandiere">
<input type="button" id="ITA" onClick="cambiaBandiera()">  </input> 
</div>
Run Code Online (Sandbox Code Playgroud)

Pet*_*ans 7

我看到你把脚本放在样式 标签而不是脚本标签之间.也许这就是它无法找到你的功能的原因?