javascript 两组radio 如何让其在每组各有其中一个值选中时相乘得到结果 任意一组没有任何选中时报错
<formname="f1"><p><h3>Tickettype:</h3></p><p><inputtype="radio"name="r1"value="50"/>A...
<form name="f1">
<p><h3>Ticket type:</h3></p>
<p><input type="radio" name="r1" value="50"/>Admission to the conference only</p>
<p><input type="radio" name="r1" value="75"/>Admission to the conference and exhibition</p>
<p><input type="radio" name="r1" value="100"/>Admission to the conference, exhibition and all screenings</p>
</form>
<form name="f3">
<p><h3>Delegate type:</h3></p>
<p><input type="radio" name="r3" value="2"/>General attendee</p>
<p><input type="radio" name="r3" value="1.5"/>Presenter</p>
<p><input type="radio" name="r3" value="1"/>Student</p>
</form> 展开
<p><h3>Ticket type:</h3></p>
<p><input type="radio" name="r1" value="50"/>Admission to the conference only</p>
<p><input type="radio" name="r1" value="75"/>Admission to the conference and exhibition</p>
<p><input type="radio" name="r1" value="100"/>Admission to the conference, exhibition and all screenings</p>
</form>
<form name="f3">
<p><h3>Delegate type:</h3></p>
<p><input type="radio" name="r3" value="2"/>General attendee</p>
<p><input type="radio" name="r3" value="1.5"/>Presenter</p>
<p><input type="radio" name="r3" value="1"/>Student</p>
</form> 展开
2个回答
展开全部
这个还没人回答啊。
那么你这个怎么触发呢?按钮?
为什么用2个form。
<html>
<body >
<form name="f1">
<p><h3>Ticket type:</h3></p>
<p><input type="radio" name="r1" value="50"/>Admission to the conference only</p>
<p><input type="radio" name="r1" value="75"/>Admission to the conference and exhibition</p>
<p><input type="radio" name="r1" value="100"/>Admission to the conference, exhibition and all screenings</p>
</form>
<form name="f3">
<p><h3>Delegate type:</h3></p>
<p><input type="radio" name="r3" value="2"/>General attendee</p>
<p><input type="radio" name="r3" value="1.5"/>Presenter</p>
<p><input type="radio" name="r3" value="1"/>Student</p>
</form>
<input type="button" value="测试"name="" onclick="test()">
<script>
function test(){
var r1=document.getElementsByName("r1");
var r3=document.getElementsByName("r3");
var r1Val="",r3Val="";
for(var i=0;i<r1.length;i++){
if(r1[i].checked){
r1Val=r1[i].value;
}
}
if(r1Val==""){
alert("您未选择Ticket type:");
return;
}
for(var i=0;i<r3.length;i++){
if(r3[i].checked){
r3Val=r3[i].value;
}
}
if(r3Val==""){
alert("您未选择Delegate type:");
return;
}
alert(parseFloat(r1Val)*parseFloat(r3Val));
return parseFloat(r1Val)*parseFloat(r3Val);
}
</script>
</body>
</html>
那么你这个怎么触发呢?按钮?
为什么用2个form。
<html>
<body >
<form name="f1">
<p><h3>Ticket type:</h3></p>
<p><input type="radio" name="r1" value="50"/>Admission to the conference only</p>
<p><input type="radio" name="r1" value="75"/>Admission to the conference and exhibition</p>
<p><input type="radio" name="r1" value="100"/>Admission to the conference, exhibition and all screenings</p>
</form>
<form name="f3">
<p><h3>Delegate type:</h3></p>
<p><input type="radio" name="r3" value="2"/>General attendee</p>
<p><input type="radio" name="r3" value="1.5"/>Presenter</p>
<p><input type="radio" name="r3" value="1"/>Student</p>
</form>
<input type="button" value="测试"name="" onclick="test()">
<script>
function test(){
var r1=document.getElementsByName("r1");
var r3=document.getElementsByName("r3");
var r1Val="",r3Val="";
for(var i=0;i<r1.length;i++){
if(r1[i].checked){
r1Val=r1[i].value;
}
}
if(r1Val==""){
alert("您未选择Ticket type:");
return;
}
for(var i=0;i<r3.length;i++){
if(r3[i].checked){
r3Val=r3[i].value;
}
}
if(r3Val==""){
alert("您未选择Delegate type:");
return;
}
alert(parseFloat(r1Val)*parseFloat(r3Val));
return parseFloat(r1Val)*parseFloat(r3Val);
}
</script>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询