body中如下代码,想实现这样一个功能:选择每道题后,点击查看按钮,判断f,s中哪个div里的得分最多,使下面相应的div显示。
<body>
<div id="f">
第一题
<input type="radio" name="radiof1" value="1" />1分
<input type="radio" name="radiof1" value="0" />0分<br />
第二题
<input type="radio" name="radiof2" value="1" />1分
<input type="radio" name="radiof2" value="0" />0分
</div><br />
<div id="s">
第一题
<input type="radio" name="radios1" value="1" />1分
<input type="radio" name="radios1" value="0" />0分<br />
第二题
<input type="radio" name="radios2" value="1" />1分
<input type="radio" name="radios2" value="0" />0分
</div>
<input type="button" value="查看"/>
<div id="one" style="display:none">
f层得分最多
</div>
<div id="two" style="display:none">
s层得分最多
</div>
</body>
[code="html"]
function getScores() { var inputs = document.getElementsByTagName('input'); var score_f = 0; var score_s = 0; for(var i=0;i<inputs.length;i++) { var obj = inputs[i]; if(obj.getAttribute('mytag')=='f' && obj.checked) { score_f += parseInt(obj.getAttribute('value')); } else if(obj.getAttribute('mytag')=='s' && obj.checked) { score_s += parseInt(obj.getAttribute('value')); } } if(score_f>score_s) { document.getElementById('one').style.display='inline'; document.getElementById('two').style.display='none'; } else if(score_f<score_s) { document.getElementById('two').style.display='inline'; document.getElementById('one').style.display='none'; } else { document.getElementById('one').style.display='none'; document.getElementById('two').style.display='none'; } }
[/code]
考虑用 JQuery 做没有!?
如果有的话,我可以帮你 !
每个div套一层form ,并把div的ID给提交过去 后台取值就方便了 然后自己去判断