不知道为什么这个功能不会启动。检查了它,阅读了很多关于 SO 的内容,什么都没有......我确信某处有一个非常小的错误,我无法发现......
<form id="order">
<table>
<tr>
<td>
What type of pica would you like?<br>
Vegetarian, £6.50 <input type="radio" name="pica" onclick="calcul();" value="vegetarian"><br>
Meat Lover, £7.20 <input type="radio" name="pica" onclick="calcul();" value="meatLover"><br>
Hawaian, £5.5 <input type="radio" name="pica" onclick="calcul();" value="hawaian">
<br><br>
</td>
</tr>
</table>
</form>
var picaPrice = new Array();
picaPrice['vegetarian']=6.5;
picaPrice['meatLover']=7.2;
picaPrice['hawaian']=5.5;
function calcul(){
var pprice = 0;
var selectedPica = document.getElementsByName('pica');
for(var i=0; i<selectedPica.length; i++){
if(selectedPica[i].checked) {
alert('selected');
}
else { alert('not selected') }
}
}
完毕。谢谢您的帮助