还要研究一下jQuery。
script.js
$(document).ready(function(){
$('#checkAll').click(function(){updateCheckBoxStatus(this);});
}
function updateCheckBoxStatus(currentCheckBox)
{
var state=currentCheckBox.checked;
var parentTables=jQuery(currentCheckBox).parents("table");
var parentTable=parentTables[0];
jQuery(parentTable).find(":checkbox").each(function()
{this.checked=state;}); //找到这个表格里面所有的checkbox,选上。
}
使用
<script type="text/javascript" src="<%= request.getContextPath() %>/scripts/jquery.js"></script>
<script type="text/javascript" src="<%= request.getContextPath() %>/scripts/script.js"></script>
<table>
<tr>
<th>
<input type="checkbox" id="checkAll"/> 全选/反选的" 父亲多选框"
</th>
</tr>
<c:forEach var="news" items="#{newsBean.list}">
<tr>
<td>
<input type="checkbox" name="oids" id="oo" value="${news.ID}"/> 子多选框
</td>
</tr>
</c:forEach>
</table>
附件:
jquery.js在csdn空间5文件夹中