为什么我提交号码时这个脚本不会运行? (目的是临时计数器缓慢递减到用户输入)
var s,t,d;
s = document.getElementById('start');
t = document.getElementById('temp');
d = document.getElementById('display');
startChange = function(){
var v,nt,diff,timelapse,decrease,decreaseit,loop;
v = +d.value;
nt = +t.value;
diff = v-nt;
timelapse = 500; //set to whatever you like
decrease = .2;
decreaseit = function(){
var v = d.value;
if(v>=(nt+decrease)){
loop = setTimeout(function(){
d.value = (v-decrease).toFixed(1);
decreaseit();
},timelapse)
} else clearInterval(loop);
}
decreaseit();
}
s.onclick = startChange;
HTML
<input id="display" type="text" value="7.2" disabled>
<input id="temp" type="text">
<button type="button" id="start">Set temp</button>
答案 0 :(得分:3)
因为您的s
变量正在寻找ID为“start”的元素,而您的按钮的ID是“startChange”。