Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [js] usuwanie ostatniego wiersz z tabeli statycznej
skowron-line
post 23.11.2007, 12:09:20
Post #1





Grupa: Zarejestrowani
Postów: 4 340
Pomógł: 542
Dołączył: 15.01.2006
Skąd: Olsztyn/Warszawa

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


Witam. Moze na początek kod
  1. <head>
  2. <script type="text/javascript">
  3. function removeRow(){
  4. var oTable = document.getElementById('oTable');
  5. oTable.removeChild(oTable.lastChild);
  6. }
  7. </script>
  8. </head>
  9. <body>
  10. <input type="button" onclick="removeRow();" value="remove">
  11. <table border="1" id="oTable">
  12. <tr id="r1">
  13. <td>1</td><td>1</td>
  14. </tr>
  15. <tr id="r2">
  16. <td>2</td><td>2</td>
  17. </tr>
  18. <tr id="r3">
  19. <td>3</td><td>3</td>
  20. </tr>
  21. </table>
  22. </body>
  23. </html>

i pytanie jak usunac ostatni wiersz z tej tabeli
bo kod ktory ujety jest w znaczniki </script> usuwa cala tabele a nie ostatni wiersz.
Dziekuje i pozdrawiam


--------------------
I'm so fast that last night I turned off the light switch in my hotel room and was in bed before the room was dark - Muhammad Ali.
Peg jeżeli chcesz uprawiać sex to dzieci muszą wyjść, a jeżeli chcesz żeby był dobry ty też musisz wyjść - Al Bundy.

QueryBuilder, Mootools.net, bbcradio1::MistaJam
http://www.phpbench.com/
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 3)
nospor
post 23.11.2007, 12:29:01
Post #2





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




lastChild w skazuje na TBODY a nie na wiersz.

Kod
function removeRow(){
var oTable = document.getElementById('oTable');
var lastTr = oTable.rows[oTable.rows.length-1];
lastTr.parentNode.removeChild(lastTr);
}


Ale takie rzeczy to sie zalatwia zwyklym alert() tongue.gif


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
skowron-line
post 23.11.2007, 12:38:07
Post #3





Grupa: Zarejestrowani
Postów: 4 340
Pomógł: 542
Dołączył: 15.01.2006
Skąd: Olsztyn/Warszawa

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


Cytat(nospor @ 23.11.2007, 12:29:01 ) *
Ale takie rzeczy to sie zalatwia zwyklym alert() tongue.gif

Jak mam to rozumiec??


--------------------
I'm so fast that last night I turned off the light switch in my hotel room and was in bed before the room was dark - Muhammad Ali.
Peg jeżeli chcesz uprawiać sex to dzieci muszą wyjść, a jeżeli chcesz żeby był dobry ty też musisz wyjść - Al Bundy.

QueryBuilder, Mootools.net, bbcradio1::MistaJam
http://www.phpbench.com/
Go to the top of the page
+Quote Post
nospor
post 23.11.2007, 12:45:17
Post #4





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Masz to rozumieć tak:
Jesteś chlopie na forum tyle czasu, że mogłbyś się wkoncu nauczyć sam diagnozować tak proste błędy, przy użyciu banalnego alert:
Kod
alert(oTable.lastChild);

I już byś wiedział, że lastChild nie wskazuje na wiersz (tak jak sądziles ze wskazuje). Mając już tę cenną informację może zaczęło by juz coś świtać w tunelu smile.gif


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post

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: 14.08.2025 - 04:26