(function() {
var count = {
digit: 0,
increment: function() {
var interval = setInterval(function() {
if (++count.digit == 10) {
clearInterval(interval);
count.decrement();
}
var update = document.getElementById("liveUpdate");
update.innerHTML = count.digit;
}, 500);
},
decrement: function() {
var interval = setInterval(function() {
if (--count.digit == -1) {
clearInterval(interval);
}
}, 500);
}
};
count.increment();
})();
멈추지 만 내려 가지 않습니까? 무엇이 문제 일 수 있습니까?왜 간단한 자바 스크립트 증가 및 감소 방법이 작동하지 않습니까?
귀하의 코드가 정확한지,하지만 당신은'update' 요소에'digit'를 표시하는 것을 잊지 :
시도 (또는 해당 JSFiddle 확인). – jerone