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

各位高手都进来看看,一个简单的问题
ID   姓名     部门       岗位  
  8     8           人事       编码  
  9     8           后勤       维修  

ID号前面有个 <checkbox> 多选框,当我选中一个多选框的时候,我怎样才能知道我选择的是哪一行数据


------解决方案--------------------
<script>
function check()
{
o = document.f.getElementsByTagName( "input ");
checks = new Array();
for(c=0; c <o.length; c++)
{
if(o[c].type== "checkbox " && o[c].checked) checks[checks.length]=o[c].value;
}
alert( "选择了: "+checks);
return false;
}
</script>
<form name= "f " onsubmit= "return check() ">
<input type= "checkbox " name= "c " value= "1 "> 1
<input type= "checkbox " name= "c " value= "2 "> 2
<input type= "checkbox " name= "c " value= "3 "> 3
<input type= "checkbox " name= "c " value= "4 "> 4
<input type= "checkbox " name= "c " value= "5 "> 5
<input type= "checkbox " name= "c " value= "6 "> 6
<input type= "checkbox " name= "c " value= "7 "> 7
<input type= "checkbox " name= "c " value= "8 "> 8
<input type= "checkbox " name= "c " value= "9 "> 9
<input type= "checkbox " name= "c " value= "10 "> 10
<input type= "submit ">
</form>
------解决方案--------------------
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<title> new page </title>
<script>
function a(obj){
if(obj.checked){
obj=obj.parentNode;
var str= " ";
while(obj.nextSibling){
obj=obj.nextSibling;
str+=obj.innerText;
}
alert( "你选中的数据为: "+str);
}
}
</script>
</head>
<body>
<table border= "1 " width= "100% " id= "table1 ">
<tr>
<td> <input type=checkbox onclick=a(this)>   </td>
<td> ID  </td>
<td> 姓名  </td>
<td> 部门  </td>
<td> 岗位  </td>
</tr>
<tr>
<td> <input type=checkbox onclick=a(this)>   </td>
<td> 8  </td>
<td> 8  </td>
<td> 人事  </td>
<td> 编码  </td>
</tr>
<tr>
<td> <input type=checkbox onclick=a(this)>   </td>
<td> 9  </td>
<td> 8  </td>
<td> 后勤  </td>
<td> 维修  </td>
</tr>
</table>
</body>
</html>