struts 中多组radio button的处理
作个考试系统,选择题,四个选项。
每个题有自己的分值,做完提交后 然后统计分数
这个要怎么实现呢?(struts中)
------解决方案--------------------页面上这样写
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=GBK ">
<title> test </title>
<script type= "text/javascript ">
</script>
</head>
<body>
<form action= "# ">
题目1:问题问题问题? <BR>
A. <input type= "radio " name= "answer1 " value=A> <BR>
B. <input type= "radio " name= "answer1 " value=B> <BR>
C. <input type= "radio " name= "answer1 " value=C> <BR>
D. <input type= "radio " name= "answer1 " value=D> <BR>
</form>
</body>
</html>
然后到action中,request.getParameter( "answer1 ");就可以取到选中的答案的value,然后判断就知道回答的对不对了
------解决方案-------------------- <input type= "radio " name= "jf " value= "jfa "/>
<input type= "radio " name= "jf " value= "jfb "/>
<input type= "radio " name= "jf " value= "jfc "/>
<input type= "radio " name= "jf " value= "jfd "/>
名字相同,值不同就行了呗!
根据名字取到值!
------解决方案--------------------只能一道题比较一次,要不你怎么能知道这个对不对呢
但是name可以定义的规则一些
如:第一题的name=answer0,第2题的name=answer1...
然后循环来处理
for (int i = 0; i < 20; i++)
{
request.getParameter( "answer "+i);
//接着做比较加分处理.
}