mirror of
https://gitlab.com/tutorial-java-rafa-munoz/tutorial-java-2024-25/LMSGI-2024-25.git
synced 2025-11-09 18:03:06 +01:00
32 lines
1003 B
HTML
32 lines
1003 B
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
|
<script>
|
|
function leerObjeto() {
|
|
// Pedir datos al usuario con prompt()
|
|
let nombre = prompt("Introduce tu nombre:");
|
|
let edad = prompt("Introduce tu edad:");
|
|
let ciudad = prompt("Introduce tu ciudad:");
|
|
|
|
// Crear el objeto con los datos introducidos
|
|
let usuario = {
|
|
nombre: nombre,
|
|
edad: parseInt(edad), // Convertir a número
|
|
ciudad: ciudad
|
|
};
|
|
|
|
// Mostrar el objeto como JSON en una alerta
|
|
alert(JSON.stringify(usuario, null, 2));
|
|
|
|
// También mostrarlo en el div de la página
|
|
document.getElementById("resultado").innerText = JSON.stringify(usuario, null, 2);
|
|
}
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<button onclick="leerObjeto()">Ingresar datos</button>
|
|
<pre id="resultado"></pre>
|
|
</body>
|
|
</html>
|