<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" language="javascript">
var cake_prices = new Array();
cake_prices["Round6"]=20;
cake_prices["Round8"]=25;
cake_prices["Round10"]=35;
cake_prices["Round12"]=75;
function getCakeSizePrice() {
var cakeSizePrice=0;
var theForm=document.forms["myForm"];
var selectedCake = document.getElementsByName("selectedcake");
for(var i = 0; i < selectedCake.length; i++) {
if(selectedCake[i].checked) {
var cakeSizePrice = cake_preces[selectedCake[i].value];
break;
}
}
alert("价格是"+parseInt(cakeSizePrice));
}
</script>
</head>
<body>
<form name="myForm" >
<label> 1)选一个正确的</label><br />
<input type="radio" name="selectedcake" id="roud6" value="Round6"
/>
Round cake 6" - serves 8 people ($20)<br />
<input type="radio" name="selectedcake" id="round8" value="Round8"
/>
Round cake 8" - serves 12 people ($25)<br />
<input type="radio" name="selectedcake" id="round10" value="Round10" />
Round cake 10" - serves 16 people($35)<br />
<input type="radio" name="selectedcake" id="round12" value="Round12"/>
Round cake 12" - serves 30 people($75)<br />
<input type="button" value="提交" name="area" onclick="getCakeSizePrice()"/>
</form>
</body>
JS从单选框中选择一个值后,点击提交后显示出该值!请问我的代码怎么修改啊啊?
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- 斯洛文尼亚旅游 2015-01-13 06:41关注
变量名错了
var cakeSizePrice = cake_preces[selectedCake[i].value];
===>
var cakeSizePrice = cake_prices[selectedCake[i].value];
解决 无用评论 打赏 举报
悬赏问题
- ¥15 ChatGPT网络被篡改怎么办?
- ¥50 ID中开关量采样信号通道、以及程序流程的设计
- ¥15 U-Mamba/nnunetv2固定随机数种子
- ¥15 vba使用jmail发送邮件正文里面怎么加图片
- ¥15 vb6.0如何向数据库中添加自动生成的字段数据。
- ¥20 在easyX库下编写C语言扑克游戏跑的快,能实现简单的人机对战
- ¥15 svpwm波形异常求解答
- ¥15 STM32——硬件IIC从机通信代码实现
- ¥15 微生物组数据分析--微生物代谢物
- ¥30 求一跃动小子保卫主公Java算法实现