var oTxt = document.getElementById("form_txt"); var val = ["车载手机支架","华硕笔记本","恒温条奶器","苏泊尔电磁炉","美的电压锅","摄影仪家用","小米手机"]; var time1 = null; var i=1; oTxt.value = val[0]; time1 = setInterval(function setVal(){ if(i>=val.length){ i=0; oTxt.value = val[0]; i++; }else{ oTxt.value = val[i]; i++; } },3000); oTxt.onfocus = function(){ clearInterval(time1); oTxt.value = ""; oTxt.style.color = "rgb(51,51,51)"; } oTxt.onblur = function(){ clearInterval(time1); if(oTxt.value==""){ oTxt.value = val[i];?????? oTxt.style.color = "rgb(153,153,153)"; } }
3 回答
李晓健
TA贡献1036条经验 获得超461个赞
var oTxt = document.getElementById("form_txt"); var val = ["车载手机支架", "华硕笔记本", "恒温条奶器", "苏泊尔电磁炉", "美的电压锅", "摄影仪家用", "小米手机"]; var time1 = null; var i = 1; oTxt.value = val[0]; //把它封装成一个方法 可以供多处调用 function openTimmer() { time1 = setInterval(function{ if (i >= val.length) { i = 0; oTxt.value = val[0]; i++; } else { oTxt.value = val[i]; i++; } }, 3000); } //页面加载时调用一次 openTimmer(); oTxt.onfocus = function () { clearInterval(time1); oTxt.value = ""; oTxt.style.color = "rgb(51,51,51)"; } oTxt.onblur = function () { clearInterval(time1); if (oTxt.value == "") { oTxt.value = val[i]; //?????? 这里再调用一次 openTimmer() oTxt.style.color = "rgb(153,153,153)"; } }
添加回答
举报
0/150
提交
取消