Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript]Pierwszy czas inny w setInterval
Mike122
post
Post #1





Grupa: Zarejestrowani
Postów: 253
Pomógł: 1
Dołączył: 12.04.2006

Ostrzeżenie: (0%)
-----


Napisałem następujący skrypt który podaję niżej działa prawie tak jak ma działać. Mam jeden problem chodzi o to że za 1 razem (1 raz po wczytaniu, odświeżeniu witryny) ma odliczyć czas 2000 ms (2 sekundy) a później już ma cały czas odliczać czas 5000 (5 sek.) a nie 2.
Proszę o pomoc.

  1. <script type="text/javascript">
  2. function numberFormat(nStr){
  3. nStr += '';
  4. x = nStr.split('.');
  5. x1 = x[0];
  6. x2 = x.length > 1 ? '.' + x[1] : '';
  7. var rgx = /(\d+)(\d{3})/;
  8. while (rgx.test(x1))
  9. x1 = x1.replace(rgx, '$1' + '.' + '$2');
  10. return x1 + x2;
  11. }
  12.  
  13. function getUp(a,b){
  14. a = document.getElementById(a);
  15. a.innerHTML = a.innerHTML;
  16. a.innerHTML = a.innerHTML.replace(new RegExp("[\.]+","g"),"");
  17. a.innerHTML = a.innerHTML.replace(new RegExp("[^\\d.]+","g"),"");
  18. a.innerHTML = a.innerHTML.replace(new RegExp(",","g"),".");
  19. a.innerHTML=+(a.innerHTML || 0)+b;
  20. a.innerHTML = numberFormat(a.innerHTML);
  21. }
  22. setInterval("getUp('test',1)", 2000);
  23. setInterval("getUp('test2',3)", 2000);
  24.  
  25. <span id="test">1.000</span>
  26. <span id="test2">3.000</span>
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 23.08.2025 - 03:54