1 초마다 1 씩 변수를 증가시키는 가장 간단한 방법은 무엇입니까? 당신은 다시 그것을 해제해야하는 경우간단한 jquery second counter
답변
var counter = 0;
setInterval(function() {
++counter;
}, 1000);
는 또한,이 수 가능 그 :
var counter = 0;
var myInterval = setInterval(function() {
++counter;
}, 1000);
// to stop the counter
clearInterval(myInterval);
가장 간단한 방법은 x++
이 당신의 증가로 대체 할 수 setInterval("x++",1000);
있다. 예 :
자바 스크립트/jQuery를
var x=0;
setInterval("x++",1000); // Increment value every second
// Let's just add a function so that you can get the value
$(document).ready(function() {
$("#showval").click(function(){
alert(x);
});
});
HTML
<a href="#" id="showval">Show value</a>
'setInterval ("x ++", 1000);'은 묵시적인 eval()을 사용합니다. 대부분의 경우 문제는 아니지만 기술적으로 보안 위험이 아닙니까? –
그렇다면 왜 비활성화하지 않았습니까? 여전히 변수를 늘리는 가장 간단한 방법입니다. –
더 좋은 방법은 폐 기능을 통해입니다 :
function setIntervalTimes(i_func, i_sleep, i_timesRun){
var timesRun = 0;
var interval = setInterval(function(){
timesRun += 1;
if(timesRun === i_timesRun){
clearInterval(interval);
}
i_func();
}, i_sleep);
},
왜 이것이 허용 된 답변보다 나은지 설명해 주시겠습니까? – AXL
기능 타이머 (세코 NDS 요소)
저자 : ZMORA JLB
이메일 : zmorajlb [원숭이] gmail.com
충전 기능 타이머 포함 :
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+ ((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)) {while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'}; c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('2 p=\'- s tńu -\';h m(c){2 g=d.f(c/r);2 i=d.f((c/e)%e);2 8=c%e;2 4=\'\';7(g>0){4=4+\'\'+g+\' w \'}7(i>0){4=4+\'\'+i+\' q \'}7(8>0){4=4+\'\'+8+\' v\'}y 4}h D(8,j,E){2 l=b a();2 5=b a();2 o=b a();2 9=b a();9=8;l=(x*d.f(d.B()*6)+1)*3;5=0;o=A(h(){k=9-5;7(5<9){5++}7(5==9){$(\'#\'+j).n(p)}z{$(\'# \'+j).n(m(k))}},C)}',41,41,'||var||out|counter||if|seconds|destination|Array|new|val|Math|60|floor|hours|function|minutes|element|remaining|number|secondsToText|html|interval|end_text|minut|3600|budowa|zako|czona|sekund|godzin|33|return|else|setInterval|random|1000|timer|method'.split('|'),0,{}))
사용
을$(document).ready(function() {
timer(8, 'time1'); // seconds and element
timer(3605, 'time2'); // seconds and element
});
first: <span>Counting "8" seconds</span>
<span id="time1">--:--</span>
초 : 세는 "3605"초 - : -
- 1. jQuery counter question
- 2. php form submit counter
- 3. IE counter-progress (CSS)
- 4. Counter ++ in Parallel.ForEach
- 5. Jquery, 간단한 애니메이션으로 반복하십시오.
- 6. 자바 스크립트 지원 Second Life의 웹 브라우저
- 7. jQuery char counter logic을 디버그하는 데 도움이 필요합니다.
- 8. IP to counter in drupal
- 9. Python Threading with a Counter
- 10. Hibernate.initialize()와 second-level 캐시
- 11. Second Life의 유용한 개발자 리소스
- 12. Java Spring NtlmProcessingFilter second controller
- 13. Second Life의 기술 스택은 무엇입니까?
- 14. hibernate second level ehcache miss
- 15. 배열을 제품별로 정렬하는 방법 [counter] .getProductTitle()?
- 16. pygtk treestore (Python)에 Counter() 목록 추가하기
- 17. 간단한 jquery 팝업
- 18. 실망스럽게 간단한 jQuery 문제
- 19. 간단한 jquery 질문
- 20. 간단한 JQuery 툴팁 만들기?
- 21. 간단한 jQuery AJAX 질문
- 22. 간단한 jQuery 질문
- 23. jQuery 간단한 탭
- 24. 간단한 jquery 플러그인
- 25. 간단한 jquery 내비게이션
- 26. jquery 간단한 모달
- 27. 간단한 jQuery 슬라이더?
- 28. 간단한 jQuery 애니메이션
- 29. 간단한 JQuery 팝업 최대
- 30. 간단한 아약스와 jquery ajax
@ShintoJoseph - 당신은이 DOM에 자신을 추가 믿을 수 없어 당신은 의미합니까? 그것은 질문이 아니었고,이 대답은 거의 5 년간 받아 들여졌습니다. –
네, 고마워요. –