Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [HTML][JavaScript]Gwiazdki do oceniania
zavada
post
Post #1





Grupa: Zarejestrowani
Postów: 68
Pomógł: 6
Dołączył: 15.06.2009
Skąd: Kraków

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


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ę.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Pawel_W
post
Post #2





Grupa: Zarejestrowani
Postów: 1 675
Pomógł: 286
Dołączył: 15.06.2009
Skąd: Wieliczka

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


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. }


Ten post edytował Pawel_W 20.07.2009, 19:51:56
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: 13.10.2025 - 10:15