Ver Mensaje Individual
  #1 (permalink)  
Antiguo 06/04/2013, 12:15
Avatar de Fernarey1810
Fernarey1810
 
Fecha de Ingreso: noviembre-2008
Mensajes: 214
Antigüedad: 15 años, 5 meses
Puntos: 1
Agregar atributo a distintas celdas TD de una tabla

Estoy creando una tabla mediante javascript:
Código Javascript:
Ver original
  1. for (f = 0; f <= 5; f++){
  2.    
  3.     tabla.insertRow(f);
  4.            
  5.     for (c = 0; c <= 5; c++){
  6.         tabla.rows[f].insertCell(c);                                   
  7.     }                      
  8. }

Lo que no se al crearla de esta manera es como agregarle los atributos:
Código HTML:
Ver original
  1. <tr>
  2.         <td width="5" height="5"></td>  <!--POR EJ aca fila 0 el primer td tiene 2 atributos-->
  3.         <td width="5"></td>
  4. </tr>
  5.  <tr>
  6.         <td height="5"></td>                  <!-- POR EJ aca fila 1 el primer td tiene 1 atributo-->
  7.         <td></td>
  8. </tr>

INTENTABA HACERLO DE ESTA FORMA PERO ANDA MAL NOSE PORQUE

Código Javascript:
Ver original
  1. td1.setAttribute("width", "5");         td1.setAttribute("height", "5");
  2. td3.setAttribute("height", "5");
  3.  
  4. for (f = 0; f <= 5; f++){
  5.     tabla.appendChild(tr);
  6.    
  7.            
  8.     for (c = 0; c <= 5; c++){
  9.        
  10.         if (c == 0 && f == 0) {
  11.             tr.appendChild(td1);   
  12.         }
  13.         if (c > 0 && c <= 10) {
  14.             tr.appendChild(td2);
  15.         }
  16.         if (c == 0 && f > 0) {
  17.             tr.appendChild(td3);
  18.         }              
  19.                                    
  20.     }
  21. }
esta ultima forma agrega bien los atributos pero me crea mal la tabla, la arma mal

Última edición por Fernarey1810; 06/04/2013 a las 12:20