Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" />
- <meta http-equiv="X-UA-Compatible" content="IE=edge" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <title>Document</title>
- </head>
- <body>
- <div class="contenedor"></div>
- </body>
- <script defer>
- const contenedor = document.querySelector(".contenedor");
- const arrayBotones = ["uno", "dos", "tres", "cuatro"];
- arrayBotones.forEach((btn) => {
- const boton = document.createElement("button");
- boton.innerText = btn; // btn se reemplaza por cada string que contiene el array
- boton.setAttribute("onclick", "reconocerBoton(event)");
- contenedor.appendChild(boton);
- });
- function reconocerBoton(e) {
- const texto = e.target.innerText;
- switch (texto) {
- case "uno":
- alert("hola uno");
- break;
- case "dos":
- alert("hola dos");
- break;
- case "tres":
- alert("hola tres");
- break;
- case "cuatro":
- alert("hola cuatro");
- break;
- }
- }
- </script>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement