87,904
社区成员
发帖
与我相关
我的任务
分享
<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>
<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>
<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>
<!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>