Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Kolorowanie Wierszy
kicaj
post
Post #1





Grupa: Zarejestrowani
Postów: 1 640
Pomógł: 28
Dołączył: 13.02.2003
Skąd: Międzyrzecz/Poznań

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


Chcialbym zrobic kolorowanie wierszy w samym CSS/JS.
Zrobilem cos takiego, niesety nie dziala...
  1. onload = function color()
  2. {
  3. if( document.getElementById('wiersz').style.bgcolor == "#FF0000" )
  4. {
  5. document.getElementById('wiersz').style.bgcolor = "#0000FF";
  6. }
  7. else
  8. {
  9. document.getElementById('wiersz').style.bgcolor = "#FF0000";
  10. }
  11. }
  12.  
  13. <table border="1">
  14.  
  15. <?php
  16. //$bgcolor = "#FF0000";
  17.  
  18. while( $row = mysql_fetch_array( $results ) )
  19. {
  20. //if( $bgcolor == "#FF0000" ) // Przyklad w php, ale nie chce go stosowac
  21. //{
  22. // $bgcolor = "#0000FF";
  23. //}
  24. //else
  25. //{
  26. // $bgcolor = "#FF0000";
  27. //}
  28.  
  29. ?>
  30.  
  31. <tr>
  32. <td id="wiersz">dane...</td>
  33. </tr>
  34.  
  35. <?php
  36. }
  37.  
  38. ?>
  39.  

Jak to zrobic? Da sie w ogole?

Ten post edytował kicaj_ 26.08.2004, 16:02:03
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Vir
post
Post #2





Grupa: Zarejestrowani
Postów: 91
Pomógł: 0
Dołączył: 25.02.2004

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


Hmm, dawno tu nie byłem (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg)

Czy chodzi o coś takiego:

Kod
<html>
<head>
<script type="text/javascript">

function set() {

var allTDs = document.getElementsByTagName('TD');

var onColor = '#FF8000';
var offColor = '#E7E7DF';

for ( var i=0; i<allTDs.length; i++ )

  {
    allTDs[i].onmouseover=function(){ this.style.backgroundColor = onColor; }
    allTDs[i].onmouseout=function(){ this.style.backgroundColor = offColor; }
    allTDs[i].className = "bg";
  }

}


</script>
<style type="text/css">
.bg
{
  background-color: #E7E7DF;
}
</style>
</head>

<body onload="set()">

<table>
<tr>
<td>Wiersz nr 1</td>
</tr>
<tr>
<td>Wiersz nr 1</td>
</tr>
</table>

</body>
</html>


(IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif)

Ps.
Możesz 'wzbogacić' kod o kolorowanie wierszy jedynie w ramach danego elementu SPAN dopisując getElementById..

np.
Kod
<html>
<head>
<script type="text/javascript">

function set() {

var allTDs = document.getElementById('test').getElementsByTagName('TD');

var onColor = '#FF8000';
var offColor = '#E7E7DF';

for ( var i=0; i<allTDs.length; i++ )

  {
    allTDs[i].onmouseover=function(){ this.style.backgroundColor = onColor; }
    allTDs[i].onmouseout=function(){ this.style.backgroundColor = offColor; }
    allTDs[i].className = "bg";
  }

}


</script>
<style type="text/css">
.bg
{
  background-color: #E7E7DF;
}
</style>
</head>

<body onload="set()">

<table>
<tr>
<td>Wiersz nr 1</td>
</tr>
<span id="test">
<tr>
<td>Wiersz nr 1</td>
</tr>
</span>
</table>

</body>
</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: 27.12.2025 - 21:01