Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JS] Zmiana wartosci styli...
Daimos
post
Post #1





Grupa: Zarejestrowani
Postów: 1 319
Pomógł: 118
Dołączył: 26.11.2003
Skąd: Lublin

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


Witam
mam taki problem... jest sobie tekst, ktory ma ustalona klase np:
  1. <span class="abc">aslkdjalksjdasd</span>
  2. tu normalny tekst i znowu:
  3. <span class="abc">aslkdjalksjdasd</span>

teraz jak z poziomu javascript zmienic np. kolor dla wszystkich napisow umieszczonych w znacznikach span gdzie class = "abc"
nie moge wstawic ID do kazdego pola, wiec wyciaganie po getElementById odpada
chyba da sie po klasach zmieniac ogolne wartosci, tylko jak
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
abc667
post
Post #2





Grupa: Zarejestrowani
Postów: 229
Pomógł: 0
Dołączył: 29.05.2007

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


  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <meta http-equiv="Content-type"
  3. content="text/html; charset=iso-8859-2">
  4. <meta http-equiv="Content-Language" content="pl">
  5. <title>...</title>
  6. .abc { color: red; }
  7.  
  8. <script type="text/javascript">
  9.  
  10.  
  11. function getId(name)
  12. {
  13. var style = document.styleSheets[0].cssRules;
  14.  
  15. for(var i=0;i<style.length;i++)
  16. {
  17. if(document.styleSheets[0].cssRules[i].selectorText == name) return i;
  18. }
  19. return false;
  20. }
  21.  
  22. function zmienKolor(color)
  23. {
  24.  
  25. var id = getId('.abc');
  26.  
  27. document.styleSheets[0].cssRules[id].style.color = color;
  28. }
  29.  
  30.  
  31. </head>
  32.  
  33. <span class="abc">dsfdsfsdfdsfsdf</span>
  34. <a href="#n" onclick="zmienKolor('green');">zmien</a>
  35.  
  36. <span class="abc">text test text test text test text test text test text test text test text test text test text test text test text test text test </span>
  37. </body>
  38. </html>
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: 19.01.2026 - 18:54