JavaScript - HTML CSS Y JS

 
Vista:
Imágen de perfil de jesus

HTML CSS Y JS

Publicado por jesus (3 intervenciones) el 31/12/2019 04:40:05
Buenas noches soy nuevo y muy verde en esto de la programacion
Tengo un problema con un codigo que cree lo que quiero es que cuando toque un boton se cambie el background de esa div de ese color y lo mismo con el radiobutton que cambie el color de esa div
paso codigo

HTML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<DOCTYPE! html>
<html>
<head>
<title>"Ejercicios JS"</title>
<meta charset="UTF-8">
<link href="estilo.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="main">
    <div class="header">
        <input type="radio" value="roso" onclick="CambiarColor('red')">ROJO
        <br>
        <input type="radio" value="blue" onclick="CambiarColor('blue')">AZUL
        <br>
        <input type="radio" value="green" onclick="CambiarColor('green')">VERDE
        <br>
        <input type="radio" value="yellow" onclick="CambiarColor('yellow')">AMARILLO
        <br>
        <input type="radio" value="pink" onclick="CambiarColor('pink')">ROSADO
    </div>
 
 
    <div class="section">
    <br><hr><br>
    <button id='boton1' onclick="javascript:document.body.style.backgroundColor='red';">ROJO</button>
    <br><hr><br>
    <button id='boton2' onclick="javascript:document.body.style.backgroundColor='blue';">AZUL</button>
    <br><hr><br>
    <button id='boton3' onclick="javascrit:document.body.style.backgroundColor='green';">VERDE</button>
    <br><hr><br>
    <button id='boton4' onclick="javascript:document.body.style.backgroundColor='yellow';">AMARILLO</button>
    <br><hr><br>
    <button id='boton5' onclick="javascript:document.body.style.backgroundColor='pink';">ROSADO</button>
    <br><hr><br>
</div>
</div>
    <script type="text/JavaScript" src="script.js"></script>
</body>
</html>


CSS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
.header{
 
    float: right;
    border: black 2px solid;
    width: 15%;
    margin-top: 1%;
    margin-right: 2%;
}
 
.section{
    margin-top: 1%;
    margin-left: 1%;
    margin-bottom: 1%;
    height: 80%;
    width: 80%;
    border: black 2px solid;
 
}
 
.main{
    border: black 2px solid;
}


JS
1
2
3
4
5
'use strict'
 
function CambiarColor(colore){
    document.bgColor = colore;
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de joel
Val: 3.506
Oro
Ha mantenido su posición en JavaScript (en relación al último mes)
Gráfica de JavaScript

HTML CSS Y JS

Publicado por joel (895 intervenciones) el 31/12/2019 12:13:44
Hola Jesus, cuando dices que se cambie ese div, a cual te refieres al div que contiene los inputs?

Tal como lo tienes ahora, cambia el color del fondo del body
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de jesus

HTML CSS Y JS

Publicado por jesus (3 intervenciones) el 31/12/2019 13:23:25
Yo cree tres div:
- main que contiene las otras dos
- header que contiene los botones y esta dentro de la main
- section que contiene los radiobutton que esta dentro de la main junto con la header pero right

Cada div le di un border 2px solid para ver los limites

Cada boton y RB tienen de nombre colores.
Si yo presiono el boton del header rojo que cambie el background de esa div (header)
Si yo presiono el RadioButton azul que cambie el background de esa otra div (section)

Asi seria el ejercicio.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de ScriptShow
Val: 2.019
Plata
Ha mantenido su posición en JavaScript (en relación al último mes)
Gráfica de JavaScript

HTML CSS Y JS

Publicado por ScriptShow (692 intervenciones) el 31/12/2019 15:41:10
Saludos Jesús,

lo podemos hacer de varias formas... Un ejemplo:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!DOCTYPE html>
 
<html>
<head>
<title>"Ejercicios JS"</title>
<meta charset="UTF-8">
 
<style>
.header{
    float: right;
    border: black 2px solid;
    width: 15%;
    margin-top: 1%;
    margin-right: 2%;
}
 
.section{
    margin-top: 1%;
    margin-left: 1%;
    margin-bottom: 1%;
    height: 80%;
    width: 80%;
    border: black 2px solid;
}
 
.main{
    border: black 2px solid;
}
</style>
<script>
function CambiarColor(colore){
document.getElementsByClassName('header')[0].style.backgroundColor = colore;
}
</script>
</head>
<body>
<div class="main">
    <div class="header">
    <input type="radio" name="rb" value="roso" onclick="CambiarColor('red')">ROJO
    <br>
    <input type="radio" name="rb" value="blue" onclick="CambiarColor('blue')">AZUL
    <br>
    <input type="radio" name="rb" value="green" onclick="CambiarColor('green')">VERDE
    <br>
    <input type="radio" name="rb" value="yellow" onclick="CambiarColor('yellow')">AMARILLO
    <br>
    <input type="radio" name="rb" value="pink" onclick="CambiarColor('pink')">ROSADO
    </div>
    <div class="section">
    <br><hr><br>
    <button id='boton1' onclick="javascript:document.getElementsByClassName('section')[0].style.backgroundColor='red';">ROJO</button>
    <br><hr><br>
    <button id='boton2' onclick="javascript:document.getElementsByClassName('section')[0].style.backgroundColor='blue';">AZUL</button>
    <br><hr><br>
    <button id='boton3' onclick="javascrit:document.getElementsByClassName('section')[0].style.backgroundColor='green';">VERDE</button>
    <br><hr><br>
    <button id='boton4' onclick="javascript:document.getElementsByClassName('section')[0].style.backgroundColor='yellow';">AMARILLO</button>
    <br><hr><br>
    <button id='boton5' onclick="javascript:document.getElementsByClassName('section')[0].style.backgroundColor='pink';">ROSADO</button>
    <br><hr><br>
</div>
</div>
</body>
</html>

Espero sea útil.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
Imágen de perfil de jesus

HTML CSS Y JS

Publicado por jesus (3 intervenciones) el 31/12/2019 16:11:35
Que grande!!!! la verdad espero llegar a ese nivel de dominio! Un genio!!
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar