Advertisement
Guest User

v

a guest
Sep 11th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. function borrar()
  2. {
  3.  
  4. var nodo = document.getElementById('rem')
  5. nodo.parentNode.removeChild(nodo);
  6.  
  7. }
  8.  
  9.  
  10.  
  11. function multiplicar()
  12. {
  13.  
  14.  
  15. var nodo = document.getElementById('id1');
  16. var valor = nodo.value;
  17.  
  18. var num = parseInt(valor);
  19.  
  20. var tabla = document.createElement('table');
  21. tabla.setAttribute("id", "rem");
  22.  
  23. var contF = -1; //Cuenta la 1 fila como encabezado
  24.  
  25.  
  26.  
  27. //Crear columna
  28. for(var i = 0; i < num+1; i++){
  29. var fila = document.createElement('tr');
  30. //Crear fila
  31. var contH = -1;
  32. contF++;
  33. tabla.appendChild(fila);
  34. for(var j = 0; j < num+1;j++)
  35. {
  36.  
  37. contH++;
  38. //Celda
  39. var colum = document.createElement('td');
  40.  
  41. //COntenido de celda
  42. if(i == 0 && j == contH)//Cabera Columna
  43. {
  44. var numero = document.createTextNode(contH);
  45. console.log("f");
  46. colum.appendChild(numero);
  47. fila.appendChild(colum);
  48. fila.style.backgroundColor = "blue";
  49. colum.style.backgroundColor = "blue";
  50. }
  51. else if(i== contF && j == 0)//Cabezera Fila
  52. {
  53. var numero = document.createTextNode(contF);
  54.  
  55. colum.appendChild(numero);
  56. fila.appendChild(colum);
  57. fila.style.backgroundColor = "blue";
  58. colum.style.backgroundColor = "blue";
  59.  
  60. }
  61. else if(i==j)//Doble
  62. {
  63. var numero = document.createTextNode(i*j);
  64.  
  65. colum.appendChild(numero);
  66. fila.appendChild(colum);
  67. fila.style.backgroundColor = "green";
  68. colum.style.backgroundColor = "green";
  69. }
  70. else
  71. {
  72. numero = document.createTextNode(i*j);
  73. colum.appendChild(numero);
  74. fila.appendChild(colum);
  75. }
  76.  
  77.  
  78. }
  79.  
  80. }
  81.  
  82. document.body.appendChild(tabla);
  83.  
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement