Ver Mensaje Individual
  #3 (permalink)  
Antiguo 05/06/2012, 12:24
Avatar de emprear
emprear
Colaborador
 
Fecha de Ingreso: junio-2007
Ubicación: me mudé
Mensajes: 8.388
Antigüedad: 17 años
Puntos: 1567
Respuesta: Obtener Datos de una Tabla

Basicamente lo que necesitas es una función que,
1. Identifique la fila sobre la que trabajás
2. Recorrer las celdas para esa fila, y extraer los valores

Para el tema del color, habiendo identificado la fila, le cambiás la propiedad style.backgroundColor también con el javascript, aunque ya es más complejo cuando se quire que al clickearla de vuelta regrese a su color, ó que tambien lo haga al hacer el out del mouse, hay variantes muy específicas, todo depende de lo que quieras hacer


ejemplo
Código HTML:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2.    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <title>Recuperar datos de celdas en una fila</title>
  5. <style type="text/css">
  6. /*<![CDATA[*/
  7. tr{
  8. background: cyan;
  9. }
  10. /*]]>*/
  11. <script type="text/javascript">
  12. //<![CDATA[
  13. function recuperarFila(idfila) {
  14. var elTableRow = document.getElementById(idfila);
  15. elTableRow.style.backgroundColor =(elTableRow.style.backgroundColor=="green")?'cyan':'green';
  16.  
  17. if(elTableRow.style.backgroundColor == 'green'){
  18. var elTableCells = elTableRow.getElementsByTagName("td");
  19.     for (var i=0; i<elTableCells.length; i++) {
  20.     alert(elTableCells[i].innerHTML);
  21.     }
  22. }
  23. }
  24. //]]>
  25. </head>
  26. <table border="1" width="50%">
  27. <tr id="fila_uno" onclick="recuperarFila(this.id)">
  28. <td>celda 1</td><td>celda 2</td>
  29. </tr>
  30. <tr id="fila_dos" onclick="recuperarFila(this.id)">
  31. <td>celda 3</td><td>celda 4</td>
  32. </tr>
  33. <tr id="fila_tres" onclick="recuperarFila(this.id)">
  34. <td>celda 5</td><td>celda 6</td>
  35. </tr>
  36. </body>
  37. </html>


Saludos
__________________
La voz de las antenas va, sustituyendo a Dios.
Cuando finalice la mutación, nueva edad media habrá
S.R.