日期:2014-05-16  浏览次数:20434 次

按钮背景色循环改变
function change(ch){
var num=document.getElementById("dd_scroll");
if(ch=="one"){
num.src=1+".jpg";
}else if(ch=="two"){
num.src=2+".jpg";
}else if(ch=="three"){
num.src=3+".jpg";
}else if(ch=="four"){
num.src=4+".jpg";
}else if(ch=="five"){
num.src=5+".jpg";
}
}
var tp;
var i=1;
function move(){
document.getElementsByTagName('div')[36].onmouseover=stopNow;
  document.getElementsByTagName('div')[36].onmouseout=goon;
var num=document.getElementById("dd_scroll");
num.src=i+".jpg";
i++;
if(i>5){
i=1;
}
}
  tp=setInterval("move()",1000);

function stopNow(){
clearTimeout(tp);
}
function goon(){
  tp=setInterval("move()",1000);
}
图片是循环显示的,如果想让按钮背景色也循环显示,怎么实现

------解决方案--------------------
楼主 把完整的代码 贴出来吧。
------解决方案--------------------
<input id="button1" type="button" value="确认" />
<script type="text/javascript">
//存储背景色
var bgs = [ '#000', '#FFF', '#06C', '#C03', '#FF3','#939' ];
//按钮背景色变化
alert("测试开始!");
var button=document.getElementById("button1");
alert(button);
//每过指定的时间执行函数一次
var count=0;
$(document).ready(change());
function change(){
window.setInterval(function(){
button.style.backgroundColor = bgs[count];
if(count!=bgs.length-1){
count++;

}
else{
count=0;
}
},1000);


}

</script>