Ich versuche eine JavaScript-Funktion zu erstellen, die es uns ermöglicht, die Rahmenfarbe eines Div basierend auf unserer Auswahl zu ändern. Wenn der Benutzer Div 1 und Gray 1 auswählt, ändert sich die Umrandungsfarbe von Div 1 zu color:#333333;
, nachdem er Make Change
getroffen hat.Ändern Sie die Rahmenfarbe der Div basierend auf der Auswahl
ist die HTML und CSS in Frage:
HTML:
<div id="div_6">
Div Selector:
<!-- Place Div Select Here -->
<select>
<option>Div 1</option>
<option>Div 2</option>
<option>Div 3</option>
</select>
<br /><br />
Color Selector:
<!-- Place Color Select Here -->
<select>
<option>Gray 1</option>
<option>Gray 2</option>
<option>Gray 3</option>
</select>
<!-- Place "Change Color" Button Here -->
<button>Change Color</button>
</div>
CSS:
/*color selectors*/
#Gray1 {
color:#333333;
}
#Gray2 {
color:#777777;
}
#Gray3 {
color:#CCCCCC;
}
So wird die Funktion diese IDs zugreifen müssen. Bitte beachten Sie die gesamten Code/Webseite hier:
Ich bin verloren, wohin man auch starten, wenn diese Funktion zu schaffen. Muss ich den Optionen verschiedene Klassen im HTML zuweisen? Vielen Dank!
EDIT Natürlich ist das Skript im <script>
Abschnitt des <head>
gehen:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="This is a simple CSS, HTML, and JS Test"/>
<title>WebToMed Website Developer Test</title>
<style>
/* Add all CSS enteries here */
#div_1 {
background: red;
display: table-cell;
text-align: left;
width: 300px;
height: 50px;
}
#div_2 {
background: green;
display: table-cell;
text-align: center;
height: 50px;
}
#div_3 {
background: blue;
display: table-cell;
text-align: right;
width: 350px;
color: #ffffff;
font-weight: bold;
text-decoration: underline;
height: 50px;
}
#div_4 {
background: yellow;
display: flex;
text-align: center;
height: 300px;
}
#div_5 {
margin-top: auto;
margin-bottom: auto;
margin-right: auto;
margin-left: auto;
}
#div_6 {
border: 3px solid black;
margin-top: 10px;
padding: 20px;
}
.container {
display: table;
width: 100%;
}
/*color selectors*/
#Gray1 {
color:#333333;
}
#Gray2 {
color:#777777;
}
#Gray3 {
color:#CCCCCC;
}
</style>
<script>
/* Add any JavaScript here */
</script>
</head>
<body>
https://jsfiddle.net/yt2u8z3w/ Hier ist eine funktionierende Geige für Sie;) –
@ mr.void Warum hast du das nicht als Antwort eingefügt? –
Mein Englisch ist zu schlecht, um die Lösung zu erklären :( –