Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Tabela, wiersz po wierszu - innerHTML
Malinaa
post 1.09.2010, 09:53:02
Post #1





Grupa: Zarejestrowani
Postów: 573
Pomógł: 6
Dołączył: 21.07.2008

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


Witam,

mam taką pętle:

[js]
for(i=0;i<response.result.length;i++) {
var div = document.createElement('div');
div.style.display = 'block';

div.innerHTML = '<table width="100%" cellspacing="1" cellpadding="0" border="0"><tr><td align="left" valign="middle" width="20">'+response.result[i].message+'</td></tr></table>';

document.getElementById('sb_Log').appendChild(div);
}
[/js]

a chciałbym mieć tak:

[js]
var div = document.createElement('div');
div.style.display = 'block';

div.innerHTML = '<table width="100%" cellspacing="1" cellpadding="0" border="0">'; // Not ok

for(i=0;i<response.result.length;i++) {
div.innerHTML = '<tr><td align="left" valign="middle" width="20">'+response.result[i].message+'</td></tr>';

document.getElementById('sb_Log').appendChild(div); // Co z tym ? ? ?
}

div.innerHTML = '</table>'; // Not ok
[/js]

Jak to zrobić, aby działało prawidłowo, tworzyło div.innerHTML krok po kroku, wiersz za wierszem, a nie jak jest teraz całe tabele?

Ten post edytował Malinaa 1.09.2010, 10:02:32


--------------------
I welcome you on the Internet >>> Design by Malina
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Malinaa
post 2.09.2010, 15:06:54
Post #2





Grupa: Zarejestrowani
Postów: 573
Pomógł: 6
Dołączył: 21.07.2008

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


Oto cały kod:

  1. var div = document.createElement('div');
  2. div.style.display = 'block';
  3. div.innerHTML = '<table width="100%" cellspacing="1" cellpadding="0" border="0">';
  4.  
  5. for(i=0;i<response.result.length;i++) {
  6. // Tlo kolumny wiersza
  7. if (i%2 != 0) {
  8. clas = 'tdWierszOne2';
  9. }
  10. else {
  11. clas = 'tdWierszOne1';
  12. }
  13. div.innerHTML += '<tr><td align="left" valign="middle" width="20" class="'+clas+'"><img src="'+usr+'" alt="IP: '+response.result[i].ip+', data: '+response.result[i].date+'" title="IP: '+response.result[i].ip+', data: '+response.result[i].date+'"></td><td align="left" class="'+clas+'"><a href="#" class="linkZwykly5" title="Profil: '+response.result[i].author+'"><b>'+response.result[i].author+':&nbsp;</b></a>&nbsp;'+response.result[i].message+'</td></tr>';
  14. }
  15. div.innerHTML += '</table>';
  16. if (response.sesja == '') {
  17. document.getElementById('sb_chatLogout').appendChild(div);
  18. }
  19. else {
  20. document.getElementById('sb_chatLog').appendChild(div);
  21. }


Przy Twoich wskazaniach wygląda tak:

[ img ]

W moim wykonaniu narazie jest tak:

[ img ]

Do końca tygodnia chcę ukończyć shoutboxa, a pierwszy raz robię coś w ajax js, będę wdzięczny za pomoc.

Chciałbym pozbyć się wierszy tabel, które generuje skrypt i mieć jedną tabele i wiele wierszy w tej jednej tabeli.

Ten post edytował Malinaa 3.09.2010, 09:31:47


--------------------
I welcome you on the Internet >>> Design by Malina
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 29.06.2025 - 05:05