Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <meta charset="UTF-8">
- <head>
- <title>Sudoku</title>
- <style>
- table {
- border-collapse: collapse;
- }
- td {
- border: 1px solid black;
- width: 30px;
- height: 30px;
- }
- input {
- width: 30px;
- height: 30px;
- }
- .boton {
- width: 100px;
- }
- #rejilla {
- float: left;
- }
- </style>
- </head>
- <body onload="crea_rejilla(document.getElementById('rejilla'))">
- <table id="rejilla">
- </table>
- <div id="botones">
- <input type="button" value="Checar" onclick="checa( )" class="boton">
- <input type="button" value="Limpiar" onclick="limpia( )" class="boton">
- </div>
- <script>
- let n = 9
- let matriz = [ ]
- function valida_input(evento) {
- let cadena = String.fromCharCode(evento.which)
- if (!/\d/.test(cadena) || this.value.length != 0) {
- evento.preventDefault( )
- }
- }
- function crea_rejilla(tabla) {
- for (let i = 0; i < n; ++i) {
- let fila = document.createElement("tr")
- for (let j = 0; j < n; ++j) {
- let celda = document.createElement("td")
- celda.id = "c" + i + "_" + j
- let entrada = document.createElement("input")
- entrada.addEventListener("keypress", valida_input)
- entrada.id = "c" + i + "_" + j
- entrada.value = "1"
- celda.appendChild(entrada)
- fila.appendChild(celda)
- }
- tabla.appendChild(fila)
- matriz.push(new Array(n))
- }
- for (let i = 0; i < n; ++i) {
- for (let j = 0; j < n; ++j) {
- matriz[i][j] = false
- }
- }
- }
- function vacia( ) {
- for (let i = 0; i < 9; ++i) {
- for (let j = 0; j < 9; ++j) {
- let casilla = document.getElementById("c" + i + "_" + j).value
- if (casilla == "" || casilla == null) {
- return true
- }
- }
- }
- return false
- }
- function checa( ) {
- console.log('entre')
- if (!vacia( )) {
- console.log("esta lleno")
- } else {
- console.log("Hay casillas vacías!")
- }
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement