在 javascript 中,如何使函数随时可以更改?我想这样做,以便当有人从下拉表单中选择不同的选项时,将出现该所选类型的图像。比如这样的:
newTexture(document.worktopForm.worktopColour.value);
function newTexture() {
var textureName = '<img src="'document.worktopForm.worktopColour.value'.jpg>';
document.getElementById("texture").innerHTML += textureName;
}
<form name="worktopForm">
<label>Choose colour of Worktop (Please select one)</label><br/>
<select name="worktopColour">
<option value="none" selected></option>
<option value="starGalaxy">Star Galaxy (££)</option>
<option value="tanBrown">Tan Brown (£££)</option>
<option value="coolColour">Cool Colour (££££)</option>
<option value="nutYellow">Nut Yellow (£££££)</option>
</select>
<div id="texture"></div></form>