情况描述:
有一个投票,每行是一个人的记录,分三列代表三个题目,每一题都是单选。
因此每一个人(每行),对应有三组共9个单选按纽 ,命名规则为 test(题号)_(被投人序号)如 test2_3 即第3个人,第二题的一组单选。
问题
在最下面设计了几个复选框,比如 全选本题A。要求勾此勾时,把所有人的这道题的A项选中。求高手赐教。谢谢,高分求。
----------------源代码开始,请拷入一个htm文件源文件中<table border="1" width="100%" id="table1">
<tr>
<td width="112">序号</td>
<td width="158">命名 test1_序号</td>
<td width="148">test2_序号</td>
</tr>
<tr>
<td width="112">1</td>
<td width="158"><p>A<input type="radio" value="A" name="test1_1">
B<input type="radio" value="B" name="test1_1"> C<input type="radio" value="C" name="test1_1"></p>
</td>
<td width="148"><p>A<input type="radio" value="A" name="test2_1">
B<input type="radio" value="B" name="test2_1"> C<input type="radio" value="C" name="test2_1"></p>
</td>
</tr>
<tr>
<td width="112">2</td>
<td width="158"><p>A<input type="radio" value="A" name="test1_2">
B<input type="radio" value="B" name="test1_2"> C<input type="radio" value="C" name="test1_2"></p>
</td>
<td width="148"><p>A<input type="radio" value="A" name="test2_2">
B<input type="radio" value="B" name="test2_2"> C<input type="radio" value="C" name="test2_2"></p>
</td>
</tr>
<tr>
<td width="112">3</td>
<td width="158"><p>A<input type="radio" value="A" name="test1_3">
B<input type="radio" value="B" name="test1_3"> C<input type="radio" value="C" name="test1_3"></p>
</td>
<td width="148"><p>A<input type="radio" value="A" name="test2_3">
B<input type="radio" value="B" name="test2_3"> c<input type="radio" value="C" name="test2_3"></p>
</td>
</tr>
<tr>
<td width="112"> </td>
<td width="158">
<p>本题全选A<input type="checkbox" name="C1" value="ON"></p>
<p>本题全选B<input type="checkbox" name="C2" value="ON"></p>
<p>本题全选<span lang="en">c</span><input type="checkbox" name="C3" value="ON"><span lang="en"> </span></p>
</td>
<td width="148">
<p>本题全选A<input type="checkbox" name="C4" value="ON"></p>
<p>本题全选B<input type="checkbox" name="C5" value="ON"></p>
<p>本题全选<span lang="en">c</span><input type="checkbox" name="C6" value="ON"><span lang="en"> </span></p></td>
</tr>
</table>------------------------------------源代码结束,请拷入一个htm文件源文件中
有一个投票,每行是一个人的记录,分三列代表三个题目,每一题都是单选。
因此每一个人(每行),对应有三组共9个单选按纽 ,命名规则为 test(题号)_(被投人序号)如 test2_3 即第3个人,第二题的一组单选。
问题
在最下面设计了几个复选框,比如 全选本题A。要求勾此勾时,把所有人的这道题的A项选中。求高手赐教。谢谢,高分求。
----------------源代码开始,请拷入一个htm文件源文件中<table border="1" width="100%" id="table1">
<tr>
<td width="112">序号</td>
<td width="158">命名 test1_序号</td>
<td width="148">test2_序号</td>
</tr>
<tr>
<td width="112">1</td>
<td width="158"><p>A<input type="radio" value="A" name="test1_1">
B<input type="radio" value="B" name="test1_1"> C<input type="radio" value="C" name="test1_1"></p>
</td>
<td width="148"><p>A<input type="radio" value="A" name="test2_1">
B<input type="radio" value="B" name="test2_1"> C<input type="radio" value="C" name="test2_1"></p>
</td>
</tr>
<tr>
<td width="112">2</td>
<td width="158"><p>A<input type="radio" value="A" name="test1_2">
B<input type="radio" value="B" name="test1_2"> C<input type="radio" value="C" name="test1_2"></p>
</td>
<td width="148"><p>A<input type="radio" value="A" name="test2_2">
B<input type="radio" value="B" name="test2_2"> C<input type="radio" value="C" name="test2_2"></p>
</td>
</tr>
<tr>
<td width="112">3</td>
<td width="158"><p>A<input type="radio" value="A" name="test1_3">
B<input type="radio" value="B" name="test1_3"> C<input type="radio" value="C" name="test1_3"></p>
</td>
<td width="148"><p>A<input type="radio" value="A" name="test2_3">
B<input type="radio" value="B" name="test2_3"> c<input type="radio" value="C" name="test2_3"></p>
</td>
</tr>
<tr>
<td width="112"> </td>
<td width="158">
<p>本题全选A<input type="checkbox" name="C1" value="ON"></p>
<p>本题全选B<input type="checkbox" name="C2" value="ON"></p>
<p>本题全选<span lang="en">c</span><input type="checkbox" name="C3" value="ON"><span lang="en"> </span></p>
</td>
<td width="148">
<p>本题全选A<input type="checkbox" name="C4" value="ON"></p>
<p>本题全选B<input type="checkbox" name="C5" value="ON"></p>
<p>本题全选<span lang="en">c</span><input type="checkbox" name="C6" value="ON"><span lang="en"> </span></p></td>
</tr>
</table>------------------------------------源代码结束,请拷入一个htm文件源文件中
解决方案 »
- 使用正则将br转换成p
- ExtJS Grid读取数据的问题 ,调用action
- 如何解决保存多个name相同的文本框的值
- 请问那位大哥知道如何在jsp中给tinyMCE添加上传本地图片到web服务器的功能?
- 请问javascript 里什么原因会导致IE中鼠标一动CPU就100%了
- 求助,2个日期加减问题.
- javascript中有server.mappath对应的方法吗?
- 求一段把当前网址写进浏览器收藏夹里的代码
- 一个Array随机排序的脚本,理论上是完全随机的,但不知道搞什么贵,实际上却不是。
- 求教gitment的初始化报错,Error: Validation Failed
- 去除数组相同的数据 (js)
- js与as3的交互问题~郁闷中~
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head> <body>
<table border="1" width="100%" id="table1">
<tr>
<td width="112">序号</td>
<td width="158">命名 test1_序号</td>
<td width="148">test2_序号</td>
</tr>
<tr>
<td width="112">1</td>
<td width="158"><p>A<input type="radio" value="A" name="test1_1">
B<input type="radio" value="B" name="test1_1"> C<input type="radio" value="C" name="test1_1"></p>
</td>
<td width="148"><p>A<input type="radio" value="A" name="test2_1">
B<input type="radio" value="B" name="test2_1"> C<input type="radio" value="C" name="test2_1"></p>
</td>
</tr>
<tr>
<td width="112">2</td>
<td width="158"><p>A<input type="radio" value="A" name="test1_2">
B<input type="radio" value="B" name="test1_2"> C<input type="radio" value="C" name="test1_2"></p>
</td>
<td width="148"><p>A<input type="radio" value="A" name="test2_2">
B<input type="radio" value="B" name="test2_2"> C<input type="radio" value="C" name="test2_2"></p>
</td>
</tr>
<tr>
<td width="112">3</td>
<td width="158"><p>A<input type="radio" value="A" name="test1_3">
B<input type="radio" value="B" name="test1_3"> C<input type="radio" value="C" name="test1_3"></p>
</td>
<td width="148"><p>A<input type="radio" value="A" name="test2_3">
B<input type="radio" value="B" name="test2_3"> c<input type="radio" value="C" name="test2_3"></p>
</td>
</tr>
<tr>
<td width="112"> </td>
<td width="158">
<p>本题全选A<input type="checkbox" name="C1" value="ON" onclick="selectResult(this,1,'A');"></p>
<p>本题全选B<input type="checkbox" name="C2" value="ON" onclick="selectResult(this,1,'B');"></p>
<p>本题全选C<input type="checkbox" name="C3" value="ON" onclick="selectResult(this,1,'C');"></p>
</td>
<td width="148">
<p>本题全选A<input type="checkbox" name="C4" value="ON" onclick="selectResult(this,2,'A');"></p>
<p>本题全选B<input type="checkbox" name="C5" value="ON" onclick="selectResult(this,2,'B');"></p>
<p>本题全选C<input type="checkbox" name="C6" value="ON" onclick="selectResult(this,2,'C');"></p></td>
</tr>
</table>
<script type="text/javascript">
//index为第几题,r为选择哪个答案
var selectResult=function(c,index,r){
var rad_result = document.getElementsByTagName("input");
for(var i=0;i<rad_result.length;i++){
if(rad_result[i].type.toLowerCase()=="radio"
&&rad_result[i].name.indexOf("test"+index)>=0
&&rad_result[i].value==r){
if(c.checked){
rad_result[i].checked=true;
}
else{
rad_result[i].checked=false;
}
}
}
unselectCheck(c);
} var unselectCheck=function(c){
var checkboxs=document.getElementsByTagName("input");
for(var i=0;i<checkboxs.length;i++){
if(checkboxs[i].type.toLowerCase()=="checkbox"&&checkboxs[i]!=c){
if(c.checked){
checkboxs[i].checked=false;
}
}
}
}
</script>
</body>
</html>
<table border="1" width="100%" id="table1">
<tr>
<td width="112">序号</td>
<td width="158">命名 test1_序号</td>
<td width="148">test2_序号</td>
</tr>
<tr>
<td width="112">1</td>
<td width="158"><p>A<input type="radio" value="A" name="test1_1">
B<input type="radio" value="B" name="test1_1"> C<input type="radio" value="C" name="test1_1"></p>
</td>
<td width="148"><p>A<input type="radio" value="A" name="test2_1">
B<input type="radio" value="B" name="test2_1"> C<input type="radio" value="C" name="test2_1"></p>
</td>
</tr>
<tr>
<td width="112">2</td>
<td width="158"><p>A<input type="radio" value="A" name="test1_2">
B<input type="radio" value="B" name="test1_2"> C<input type="radio" value="C" name="test1_2"></p>
</td>
<td width="148"><p>A<input type="radio" value="A" name="test2_2">
B<input type="radio" value="B" name="test2_2"> C<input type="radio" value="C" name="test2_2"></p>
</td>
</tr>
<tr>
<td width="112">3</td>
<td width="158"><p>A<input type="radio" value="A" name="test1_3">
B<input type="radio" value="B" name="test1_3"> C<input type="radio" value="C" name="test1_3"></p>
</td>
<td width="148"><p>A<input type="radio" value="A" name="test2_3">
B<input type="radio" value="B" name="test2_3"> c<input type="radio" value="C" name="test2_3"></p>
</td>
</tr>
<tr>
<td width="112"> </td>
<td width="158">
<p>本题全选A<input type="checkbox" name="C1" value="ON" onclick="selectid(0,1);"></p>
<p>本题全选B<input type="checkbox" name="C2" value="ON" onclick="selectid(1,1);"></p>
<p>本题全选<span lang="en">c</span><input type="checkbox" name="C3" value="ON" onclick="selectid(2,1);"><span lang="en"> </span></p>
</td>
<td width="148">
<p>本题全选A<input type="checkbox" name="C4" value="ON" onclick="selectid(0,2);"></p>
<p>本题全选B<input type="checkbox" name="C5" value="ON" onclick="selectid(1,2);"></p>
<p>本题全选<span lang="en">c</span><input type="checkbox" name="C6" value="ON" onclick="selectid(2,2);"><span lang="en"> </span></p></td>
</tr>
</table>
<script>
function selectid(cout,i){
var id = document.getElementById('table1');
var len = id.getElementsByTagName('tr').length;
for(var j=1;j<len-1;j++){
id.rows[j].cells[i].getElementsByTagName('input')[cout].checked = true ;
}
}
</script>
<tr>
<td width="112">序号</td>
<td width="158">命名 test1_序号</td>
<td width="148">test2_序号</td>
</tr>
<tr>
<td width="112">1</td>
<td width="158"><p>A<input type="radio" value="A" name="test1_1">
B<input type="radio" value="B" name="test1_1"> C<input type="radio" value="C" name="test1_1"></p>
</td>
<td width="148"><p>A<input type="radio" value="A" name="test2_1">
B<input type="radio" value="B" name="test2_1"> C<input type="radio" value="C" name="test2_1"></p>
</td>
</tr>
<tr>
<td width="112">2</td>
<td width="158"><p>A<input type="radio" value="A" name="test1_2">
B<input type="radio" value="B" name="test1_2"> C<input type="radio" value="C" name="test1_2"></p>
</td>
<td width="148"><p>A<input type="radio" value="A" name="test2_2">
B<input type="radio" value="B" name="test2_2"> C<input type="radio" value="C" name="test2_2"></p>
</td>
</tr>
<tr>
<td width="112">3</td>
<td width="158"><p>A<input type="radio" value="A" name="test1_3">
B<input type="radio" value="B" name="test1_3"> C<input type="radio" value="C" name="test1_3"></p>
</td>
<td width="148"><p>A<input type="radio" value="A" name="test2_3">
B<input type="radio" value="B" name="test2_3"> c<input type="radio" value="C" name="test2_3"></p>
</td>
</tr>
<tr>
<td width="112"> </td>
<td width="158">
<p>本题全选A<input type="checkbox" name="C1" value="ON"></p>
<p>本题全选B<input type="checkbox" name="C2" value="ON"></p>
<p>本题全选<span lang="en">c</span><input type="checkbox" name="C3" value="ON"><span lang="en"> </span></p>
</td>
<td width="148">
<p>本题全选A<input type="checkbox" name="C4" value="ON"></p>
<p>本题全选B<input type="checkbox" name="C5" value="ON"></p>
<p>本题全选<span lang="en">c</span><input type="checkbox" name="C6" value="ON"><span lang="en"> </span></p></td>
</tr>
</table>
<script>
var chk=document.getElementsByTagName("input");
for(var i=0;i<chk.length;i++){
if(chk[i].type=="checkbox"){
chk[i].onclick=function(){
var id=parseInt(this.name.substring(1));
var qId=Math.ceil(id/3);
var aId=id%3;
if(aId==0)aId=3;
document.getElementsByName("test"+qId+"_1")[aId-1].checked=this.checked;
document.getElementsByName("test"+qId+"_2")[aId-1].checked=this.checked;
document.getElementsByName("test"+qId+"_3")[aId-1].checked=this.checked;
for(var j=1;j<=3;j++)
if(this.name!=("C"+(j+(qId-1)*3)))document.getElementsByName("C"+(j+(qId-1)*3))[0].checked=false;
}
}
}
</script>