Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [HTML][JavaScript]Gwiazdki do oceniania
Forum PHP.pl > Forum > Przedszkole
zavada
Witam!
Mam trzy pliki: star.png, star_grey.png i star_bronze.png
Chcę zrobić system oceniania. Z php i mysql nie mam problemu, ale jak zrobić najeżdżanie na gwiazdki? To znaczy średnia ocen to 3/5. Więc skrypt pisze kod:

  1. <img src="star_bronze.png">
  2. <img src="star_bronze.png">
  3. <img src="star_bronze.png">
  4. <img src="star_grey.png">
  5. <img src="star_grey.png">


Ale jak zrobić to, że jak najadę na 2. gwiazdkę to wygląda tak:
  1. <img src="star_gold.png">
  2. <img src="star_gold.png">
  3. <img src="star_bronze.png">
  4. <img src="star_grey.png">
  5. <img src="star_grey.png">


A jak najadę na 4. to wygląda tak:?
  1. <img src="star_gold.png">
  2. <img src="star_gold.png">
  3. <img src="star_gold.png">
  4. <img src="star_gold.png">
  5. <img src="star_grey.png">


Wiem, wiem. Jest dużo takich tematów, ale w żadnym nie znalazłem tego, co chcę.
zavada
A coś prostszego (jakieś onmouseover i javascript) ?

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN">
  2. <meta content="text/html; charset=WINDOWS-1250" http-equiv="content-type">
  3. <title>Gwiazdki</title>
  4. <script type="text/javascript">
  5. function Rate(type, starNumber) {
  6. for (i = 1; i <= starNumber; i++) {
  7. if (type == 'over') {
  8. if (i <= rate) {
  9. starId = document.getElementById ("star" + i);
  10. starId.src = 'star.png';
  11. }
  12. else {
  13. starId = document.getElementById ("star" + i);
  14. starId.src = 'star.png';
  15. }
  16. }
  17. else if (type == 'out') {
  18. if (i <= rate) {
  19. starId = document.getElementById ("star" + i);
  20. starId.src = 'star_bronze.png';
  21. }
  22. else {
  23. starId = document.getElementById ("star" + i);
  24. starId.src = 'star_grey.png';
  25. }
  26. }
  27. }
  28. }
  29. </script>
  30. </head>
  31. <script type="text/javascript">
  32. rate = 3;
  33. for (i = 1; i <= rate; i++) {
  34. starId = document.getElementById ("star" + i);
  35. starId.src = 'star_bronze.png';
  36. }
  37. <img src="star_grey.png" id="star1" onmouseover="Rate('over', 1)" onmouseout="Rate('out', 1)">
  38. <img src="star_grey.png" id="star2" onmouseover="Rate('over', 2)" onmouseout="Rate('out', 2)">
  39. <img src="star_grey.png" id="star3" onmouseover="Rate('over', 3)" onmouseout="Rate('out', 3)">
  40. <img src="star_grey.png" id="star4" onmouseover="Rate('over', 4)" onmouseout="Rate('out', 4)">
  41. <img src="star_grey.png" id="star5" onmouseover="Rate('over', 5)" onmouseout="Rate('out', 5)">
  42. </body>
  43. </html>


Mam coś takiego. problem w tym, że jak urucchomie skrypt to musze najechać na gwiazdki, zeby zmieniły się na star_bronze.png
Jak zrobć, zeby bylo od razu
Pawel_W
body onload?

EDIT: skrypt masz poprawny, jedyne co to tutaj jest błąd
  1. <script type="text/javascript">
  2. rate = 3;
  3. for (i = 1; i <= rate; i++) {
  4. starId = document.getElementById ("star" + i);
  5. starId.src = 'star_bronze.png';
  6. }
  7. <img src="star_grey.png" id="star1" onmouseover="Rate('over', 1)" onmouseout="Rate('out', 1)">
  8. <img src="star_grey.png" id="star2" onmouseover="Rate('over', 2)" onmouseout="Rate('out', 2)">
  9. <img src="star_grey.png" id="star3" onmouseover="Rate('over', 3)" onmouseout="Rate('out', 3)">
  10. <img src="star_grey.png" id="star4" onmouseover="Rate('over', 4)" onmouseout="Rate('out', 4)">
  11. <img src="star_grey.png" id="star5" onmouseover="Rate('over', 5)" onmouseout="Rate('out', 5)">

pętla zmienia ci gwiazdki na brązowe, ale te obrazki nie istnieją, zamień to na:
  1. <img src="star_grey.png" id="star1" onmouseover="Rate('over', 1)" onmouseout="Rate('out', 1)">
  2. <img src="star_grey.png" id="star2" onmouseover="Rate('over', 2)" onmouseout="Rate('out', 2)">
  3. <img src="star_grey.png" id="star3" onmouseover="Rate('over', 3)" onmouseout="Rate('out', 3)">
  4. <img src="star_grey.png" id="star4" onmouseover="Rate('over', 4)" onmouseout="Rate('out', 4)">
  5. <img src="star_grey.png" id="star5" onmouseover="Rate('over', 5)" onmouseout="Rate('out', 5)">
  6. <script type="text/javascript">
  7. rate = 3;
  8. for (i = 1; i <= rate; i++) {
  9. starId = document.getElementById ("star" + i);
  10. starId.src = 'star_bronze.png';
  11. }
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.