Untitled
unknown
plain_text
3 years ago
752 B
8
Indexable
<!DOCTYPE html>
<html>
<head>
<title>Cambio de color de fondo al hacer clic</title>
<style>
/* Centra el botón */
.center {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
</style>
</head>
<body>
<!-- Botón para cambiar el color de fondo -->
<div class="center">
<button onclick="changeColor()">Cambia el color de fondo</button>
</div>
<script>
function changeColor() {
// Genera colores aleatorios RGB
var r = Math.floor(Math.random() * 256);
var g = Math.floor(Math.random() * 256);
var b = Math.floor(Math.random() * 256);
// Establece el nuevo color de fondo
document.body.style.backgroundColor = "rgb(" + r + "," + g + "," + b + ")";
}
</script>
</body>
</html>
Editor is loading...