日期:2014-05-17  浏览次数:20728 次

动态改变按钮背景图片IE8不能正常显示问题
.style1{
width:104px;
height:29px;
float:left;
cursor:pointer;
background-color:#FFFFFF;
background:url("images/rm/u40_original.png");
background-repeat:no-repeat;
border:0px;
outline: none;
}
.style2{
width:104px;
height:29px;  
float:left;
cursor:pointer;
background-color:#FFFFFF;
background:url("images/rm/u42_original.png");
background-repeat:no-repeat;
border:0px;
outline: none;
}
--------------------------------------------------
<input id="s1" class="style1" type="button" onclick="change(1);"/>
<input id="s2" class="style2" type="button" value="体验(0)" onclick="change(2);"/>
<input id="s3" class="style2" type="button" value="收费(0)" onclick="change(3);"/>

-----------------------
function change(num){
 
 for(id=1;id<=3;id++){
 var ss=document.getElementById('s'+id);
 if(id==num){
//$('s'+id).className="style1";
ss.className="style1";
alert(ss.className);//alert值为style1,但就是加载不了样式,firefox下正常显示
  if (num=="2") {
document.getElementById("mianfei").style.display="none";
document.getElementById("tiyan").style.display="block";
document.getElementById("shoufei").style.display="none";
}else if (num=="1") {
document.getElementById("mianfei").style.display="block";
document.getElementById("tiyan").style.display="none";
document.getElementById("shoufei").style.display="none";
}else if (num=="3") {
document.getElementById("mianfei").style.display="none";
document.getElementById("tiyan").style.display="none";
document.getElementById("shoufei").style.display="block";
}
 }else{
  ss.className="style2";
  //$('s'+id).className="style2";
 }
 }

------------------------------------
alert值为style1,但就是加载不了样式,firefox下正常显示,请问怎么改呢???

------解决方案--------------------
应该不是这里的问题,你用最简代码试一下,肯定改变样式的
HTML code

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test</title>
<style type="text/css" >
area:hover{ cursor:move; }
.btn1{ width:80px; height:26px;
    background-image:url("images/button_01.gif");
     background-repeat:no-repeat;
}
.btn2{ width:80px; height:26px;
    background-image:url("images/button_02.gif");
     background-repeat:no-repeat;
}
</style>
</head>
<body>

<script type="text/javascript">
 
    function chgstyle(o) {

        o.className = "btn2";
    
    }

</script>
  
   <input type="button" onclick="chgstyle(this)" value="&nbsp;" class="btn1" />
 
</body>
</html>