我對代碼非常陌生,但我想知道我應該使用此代碼指示什麼方向。我將在下拉菜單中選擇一種顏色,並在預覽框中顯示圖像。我需要在預覽框中同時顯示每個color1 color2和color3圖像。當其他顏色被挑選時,他們也需要能夠改變。如果任何人都可以給某種方向,這將是真棒:)哦,我也有我的圖像中的精靈下拉顯示圖像
這裏設置的是代碼,我到目前爲止有:
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
#preview {
display: block;
width: 270px;
height: 270px;
border: 1px solid black;
}
</style>
<div id="preview">
<img id="image" src="image.png" />
</div>
<form action="" id="opts">
<label for="color1">Front Color</label>
<select name="color1" id="color1">
<option value="white" selected="">white</option>
<option value="black">black</option>
<option value="red">red</option>
<option value="blue">blue</option>
<option value="gold">gold</option>
<option value="pink">pink</option>
<option value="purple">purple</option>
</select>
<br>
<label for="color2">Middle Color</label>
<select name="color2" id="color1">
<option value="white">white</option>
<option value="black">black</option>
<option value="red">red</option>
<option value="blue">blue</option>
<option value="gold">gold</option>
<option value="pink">pink</option>
<option value="purple">purple</option>
</select>
<br>
<label for="color3">Back Color</label>
<select name="color3" id="color1">
<option value="white">white</option>
<option value="black">black</option>
<option value="red">red</option>
<option value="blue">blue</option>
<option value="gold">gold</option>
<option value="pink">pink</option>
<option value="purple">purple</option>
</select>
</form>
<script>
function setcolor1() {
var img = document.getElementById("image");
img.src = this.value;
return false;
}
document.getElementById("color1").onchange = setcolor1;
}
</script>