我试图选择俱乐部并使用单选按钮显示图像和返回价格。 我卡住了,因为我无法显示图片。任何想法我可以添加什么?
<label>Select Club:</label><br>
<UL>
<label class="radiolabel"><input type="radio" name="SelectedJersy" value="MUFC" onclick="displayJersy()"> MUFC-(15€)</label><br>
<label class="radiolabel"><input type="radio" name="SelectedJersy" value="MCFC" onclick="displayJersy()"> MCFC-(20€)</label><br>
</UL>
<div id='jersy'></div>
<script type="text/javascript">
var img_Jersy = new Array();
img_Jersy["MUFC"]= "<img src='data/images/MUFC.png'>";
img_Jersy["MCFC"]= "<img src='data/images/MCFC.png'>";
var jersy_prices = new Array();
jersy_prices["MUFC"]=15;
jersy_prices["MCFC"]=10;
function displayJersy()
{
var jersyPrice=0;
var theForm = document.forms["tshirtform"];
var selectJersy = theForm.elements["SelectedJersy"];
for(var i = 0; i < selectJersy.length; i++)
{
//if the radio button is checked
if(selectJersy[i].checked)
{
jersyPrice = jersy_prices[selectJersy[i].value];
//imgJersy = img_Jersy[selectJesry[i].value];
imgJersy = img_Jersy[selectJesry[i].value];
document.getElementById("jersy").innerHTML =imgJersy;
document.getElementById('jersy').style.visibility="visible";
break;
}
return jersyPrice;
}
</script>
答案 0 :(得分:0)
我看到了几个问题。你在for循环中忘记了一个闭合的大括号。
这里有一个错字:
imgJersy = img_Jersy[**selectJesry**[i].value];
无论如何,这是一个有效的版本:http://jsfiddle.net/z92togqd/2/