<script language="javascript">
function getCheckValues(theForm) {
var values = "";
var temp;
var formlen = theForm.length;
for (var i=0;i<formlen;i++) {
var theitem = theForm.elements[i].name;
var ischeck = theitem.indexOf("selectedObjectIds",0) + 1; /* simple string search on checkbox consistent name, you change it to deleteID or whatever */
if (ischeck > 0) {
if (theForm.elements[i].checked) {
//alert(values);
values += ((values==""?"":";")+theForm.elements[i].value);
}
}
}
alert(values);
return values;
}
function getCheckValues2(theForm){
var ids="";
for(var i=0;i<theForm.elements.length;i++){
if(theForm.elements[i].type=="checkbox"){
if(theForm.elements[i].checked==true){
ids += ((ids==""?"":";")+theForm.elements[i].value);
}
}
}
alert(ids);
}
</script>
<form name="theForm">
<table>
<tr>
<td><input type="checkbox" name="selectedObjectIds" value="id1"/></td>
</tr>
<tr>
<td><input type="checkbox" name="selectedObjectIds" value="id2"/></td>
</tr>
<tr>
<td><input type="checkbox" name="selectedObjectIds" value="id3"/></td>
</tr>
<tr>
<td><input type="button" value="测试checkbox选中并得到id" οnclick="getCheckValues(theForm)"/></td>
<td><input type="button" value="测试checkbox选中并得到id" οnclick="getCheckValues2(theForm)"/></td>
</tr>
</table>
</form>