所以我有一些单选按钮:
<input type="radio" name="option" value="GDP" id="GDP_option" checked>GDP
<input type="radio" name="option" value="Population" id="Population_option" >Population
<input type="radio" name="option" value="None" id="None_option" > None
我还有一个提交按钮:
<input type="submit" name="submit" id="submit" onsubmit="changeFormula()">
和一张图片:
<img src="formula_gdp.gif" name="formula" id="formula">
当按下提交按钮时,我想根据选中的单选按钮将图像 src 更改为其他内容。这是我尝试过的:
function changeFormula(){
var radio = document.getElementsByName('option');
var formula = document.getElementsByName('formula')
if (radio[1].checked){
formula.src = "formula_gdp.gif";
}
if (radio[2].checked){
formula.src = "formula_pop.gif";
}
if (radio[3].checked){
formula.src = "formula_none.gif";
}
}