Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function borrar()
- {
- var nodo = document.getElementById('rem')
- nodo.parentNode.removeChild(nodo);
- }
- function multiplicar()
- {
- var nodo = document.getElementById('id1');
- var valor = nodo.value;
- var num = parseInt(valor);
- var tabla = document.createElement('table');
- tabla.setAttribute("id", "rem");
- var contF = -1; //Cuenta la 1 fila como encabezado
- //Crear columna
- for(var i = 0; i < num+1; i++){
- var fila = document.createElement('tr');
- //Crear fila
- var contH = -1;
- contF++;
- tabla.appendChild(fila);
- for(var j = 0; j < num+1;j++)
- {
- contH++;
- //Celda
- var colum = document.createElement('td');
- //COntenido de celda
- if(i == 0 && j == contH)//Cabera Columna
- {
- var numero = document.createTextNode(contH);
- console.log("f");
- colum.appendChild(numero);
- fila.appendChild(colum);
- fila.style.backgroundColor = "blue";
- colum.style.backgroundColor = "blue";
- }
- else if(i== contF && j == 0)//Cabezera Fila
- {
- var numero = document.createTextNode(contF);
- colum.appendChild(numero);
- fila.appendChild(colum);
- fila.style.backgroundColor = "blue";
- colum.style.backgroundColor = "blue";
- }
- else if(i==j)//Doble
- {
- var numero = document.createTextNode(i*j);
- colum.appendChild(numero);
- fila.appendChild(colum);
- fila.style.backgroundColor = "green";
- colum.style.backgroundColor = "green";
- }
- else
- {
- numero = document.createTextNode(i*j);
- colum.appendChild(numero);
- fila.appendChild(colum);
- }
- }
- }
- document.body.appendChild(tabla);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement