Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [js] PRosty skrypt a jednak..., Mały problem
miallih
post
Post #1





Grupa: Zarejestrowani
Postów: 9
Pomógł: 0
Dołączył: 29.07.2010

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


Witam, mam mały problem ze skryptem,
[JAVASCRIPT] pobierz, plaintext
  1. <table>
  2. <th colspan="5"> Rozdaj staty</th>
  3. <tr>
  4. <td>1</td><td><input type="button" id="minus_sila" value= "<"></td><td><span id="sila" >8</span></td><td><input type="button" id="plus_sila" value= ">"></td><td>5</td></tr>
  5. <tr>
  6. <td>1</td><td><input type="button" id="minus_zrecznosc" value= "<"></td><td><span id="zrecznosc" >8</span></td><td><input type="button" id="plus_zrecznosc" value= ">"></td><td>5</td></tr>
  7. </table>
  8. <script>
  9. var staty = ["sila", "zrecznosc"];
  10. for (var i = 0; i < staty.length; i++)
  11. {
  12. document.getElementById("plus_"+staty[i]).onclick = function (evt) {plus(i); };
  13. document.getElementById("minus_"+staty[i]).onclick = function (evt) {minus(i); };
  14. }
  15. function plus(i)
  16. {
  17. var e=document.getElementById(staty[i]);
  18. e.innerHTML++;
  19. }
  20. function minus(i)
  21. {
  22. var z=document.getElementById(staty[i]);
  23. z.innerHTML--;
  24. }
  25. </script>
[JAVASCRIPT] pobierz, plaintext


Skrypt z założenia prosty, ma zmieniać siłę i zręczność. jak przechodzi po pętli for, to alerty działają jak mają. Jak klikam na strzałki to nic się nie dzieje.
Oco chodzi?

Dzięki Thek, niestety i tak nie pomogło :/
Powód edycji: [thek]: Pierwszy i ostatni raz zmieniam bbcode, następny raz od razu zamykam temat
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Kemsan
post
Post #2





Grupa: Zarejestrowani
Postów: 33
Pomógł: 6
Dołączył: 30.06.2008
Skąd: Bytom

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


[JAVASCRIPT] pobierz, plaintext
  1. <table>
  2. <th colspan="5"> Rozdaj staty</th>
  3. <tr>
  4. <td>1</td>
  5. <td>
  6. <input type="button" id="minus_sila" name="add_button" value= "<">
  7. </td>
  8. <td>
  9. <span id="sila" >8</span>
  10. </td>
  11. <td>
  12. <input type="button" id="plus_sila" name="add_button" value= ">">
  13. </td>
  14. <td>5</td>
  15. </tr>
  16. <tr>
  17. <td>1</td>
  18. <td>
  19. <input type="button" id="minus_zrecznosc" name="add_button" value= "<">
  20. </td>
  21. <td>
  22. <span id="zrecznosc" >8</span>
  23. </td>
  24. <td>
  25. <input type="button" id="plus_zrecznosc" name="add_button" value= ">">
  26. </td>
  27. <td>5</td>
  28. </tr>
  29. </table>
  30. <script>
  31. var stats = [ "sila", "zrecznosc" ], elements = [ ];
  32. window.onload = function(){
  33. for( i in stats ){
  34. document.getElementById( 'plus_'+stats[ i ] ).onclick = function(){
  35. plus( this.id.split( '_' )[1] );
  36. }
  37. document.getElementById( 'minus_'+stats[ i ] ).onclick = function(){
  38. minus( this.id.split( '_' )[1] );
  39. }
  40.  
  41. elements[ stats[ i ] ] = document.getElementById( stats[ i ] );
  42. }
  43. }
  44.  
  45. function plus( i )
  46. {
  47. elements[ i ].innerHTML = parseInt( elements[ i ].innerHTML ) + 1;
  48. };
  49.  
  50. function minus( i )
  51. {
  52. elements[ i ].innerHTML = parseInt( elements[ i ].innerHTML ) - 1;
  53. };
  54. </script>
[JAVASCRIPT] pobierz, plaintext

Działa, testowałem.

Ten post edytował Kemsan 7.05.2011, 22:11:19
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: 6.10.2025 - 20:42