日期:2014-05-16  浏览次数:20302 次

javascript 两组radio 如何让其在每组各有其中一个值选中时相乘得到结果 任意一组没有任何选中时报错
<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>
javascript

------解决方案--------------------

<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" onclick="fn1()" id="r31" value="2" >General attendee</p>
<p><input type="radio" name="r3" onclick="fn1()" id="r32"  value="1.5"/>Presenter</p>
<p><input type="radio" name="r3" onclick="fn1()" id="r33"  value="1"/>Student</p>
</form>
<button onclick="Calculation()">Calculation</button>
<script>
var inputs=document.getElementsByTagName('input'),vs=[];
for(var i=0,L=inputs.length;i<L;i++) 
inputs[i].onclick=function(){
   vs[this.name=='r1'?0:1]=this.value
}
function Calculation(){
  var error=['Ticket type','Delegate type']
   if(!vs[0]) {
      alert( 'Ticket type can not be empty');
    }else if(!vs[0]) {
      alert( 'Ticket type can not be empty');
    }else
      alert( vs[0]* vs[1])
}
</script>

------解决方案--------------------
引用:
JavaScript code?123456789101112131415161718192021222324252627282930313233343536373839404142434445<script src="http://code.jquery.com/jquery-latest.js"></script><script type="text/JavaScri……

怎么可能没反应呢,这个是用JQUERY写的,
<script src="http://code.jquery.com/jquery-latest.js"></script>这行一定要加上
我重新排了下版,你从新粘上试试

<script src="http://code.jquery.com/jquery-latest.js"></script>
<