functiontoD(time){//空位补零 if(time < 10) { time = '0'+time; }else{ time = ''+ time; }
return time;//忘记return }
window.onload = function (){ var aImg = document.getElementsByTagName('img'); functiontimer(){ var oD = newDate; var str = toD(oD.getHours()) + toD(oD.getMinutes()) + toD(oD.getSeconds());
for(var i = 0; i < aImg.length; i++){ //aImg[i].src = "img/"+str[i]+".png"; 低版本 IE7 不支持 aImg[i].src = "img/"+str.charAt(i)+".png"; } }
timer(); setInterval(timer, 1000);
}
延时提示框
移入显示,移出隐藏
移出延时隐藏
简化代码
合并两个相同的 mouseover 和 mouseout
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
window,onload = function (){ var oDiv1 = document.getElementById('div1'); var oDiv2 = document.getElementById('div2'); var timer = null;
window.onload = function (){ var oDiv = document.getElementById('div1'); var oUl = oDiv.getElementsByTagName('ul')[0]; var oBtn1 = document.getElementById('btn1'); var oBtn2 = document.getElementById('btn2'); var aLi = oUl.getElementsByTagName('li'); var speed = 2;