我想改变使用javascript的元素的类。 到目前为止我做:IE6/7和ClassName(JS/HTML)
var link = document.getElementById("play_link");
link.className = "play_button";
编辑:这里是更换类名
在HTML的实际代码:
<a href="#play_link_<%=i%>" id="play_link_<%=i%>"onclick="changeCurrentTo(<%=i%>);return false;" class="play_button"></a>
在JavaScript 功能changeCurrentTo(id){ activatePlayButton(current_track); current_track = id; inactivatePlayButton(current_track); }
function inactivatePlayButton(id){
document.getElementById("recording_"+id).style.backgroundColor="#F7F2D1";
var link = document.getElementById("play_link_"+id);
link.className="stop_button";
link.onclick = function(){stopPlaying();return false;};
}
function activatePlayButton(id){
document.getElementById("recording_"+id).style.backgroundColor="";
var link = document.getElementById("play_link_"+id);
link.className = "play_button";
var temp = id;
link.onclick = function(){changeCurrentTo(temp);return false;};
}
与
.play_button{
background:url(/images/small_play_button.png) no-repeat;
width:25px;
height:24px;
display:block;
}
老班是
.stop_button{
background:url(/images/small_stop_button.png) no-repeat;
width:25px;
height:24px;
display:block;
}
的背景是一个音乐播放器。当你点击播放按钮(三角形)时,它会变成停止按钮(方形)并替换被调用的功能。
问题在于该类被更改,但在IE6和7中,新背景(此处为/images/small_play_button.png)不会立即显示。有时甚至根本不显示。有时它不会显示,但如果我稍微摇动鼠标,它就会显示。
它在FF,Chrome,Opera和Safari中完美运行,所以它是一个IE bug。我知道很难立即告诉这些信息,但如果我能得到一些有用的指示和方向的话。
Thanks-
你用什么来触发班级变更? – 2009-04-22 16:51:40
我正在使用onclick。这里是标记和js电话: – marcgg 2009-04-22 17:27:52
我使用了一个定位标记,因为没有其他标记可以在IE6中使用onclick动作正确工作,因此返回false hack。 – marcgg 2009-04-22 17:28:45