我有几个复选框,每个复选框代表个人团队ID。我上面有几个复选框,每个复选框代表一组这些团队。我希望在检查该组时检查单个团队复选框,反之亦然。当涉及到javascript时,我非常弱,这可能是基本的,但我无法弄明白。我的复选框值是在php中提取的,我试图避免使用JQuery。
------------------ PHP ---群组------------
<tr><th width="2%" class="thead1"></th><th class="thead1">Regions</th><th></th></tr>
<?php for ($i=0, $n=count( $this->regions111 ); $i < $n; $i++) {
$regions111 = $this->regions111[$i];?>
<tr><td><input type="checkbox" name="regionbox[]" value="<?php echo $regions111->id;?>"></td><td><?php echo $regions111->name;?></td></tr>
<?php }?>
-------------- PHP-个人团队ID --------------------------- < / p>
<tr >
<th width="2%" class="thead1">
<input type="button" onclick="SetAllCheckBoxes('adminForm', 'teamarray2[]',true );" value="ALL" ><input type="button" onclick="SetAllCheckBoxes('adminForm', 'teamarray2[]',false );" value="None" > <th class="thead1">Teams
</th><th class="thead1">City</th>
</tr>
<?php
for ($i=0, $n=count( $this->rows ); $i < $n; $i++) {
$row = $this->rows[$i];
?>
<tr class="etblraw<?php echo $i % 2?>"><td>
<input type="checkbox" name="teamarray2[]" value="<?php echo $row->id;?>" <?php if (in_array("$row->id",$this->henry5)){echo 'checked="checked"';}else{}?> >
</td>
<td>
<?php
echo $row->t_name;
?>
</td>
<td>
<?php echo $row->t_city;?>
</td>
</tr>
--------------------最终PHP --------------------------- -
---------------- Javascript-选择所有功能------------------
function SetAllCheckBoxes(FormName, FieldName, CheckValue)
{
if(!document.forms[FormName])
return;
var objCheckBoxes = document.forms[FormName].elements[FieldName];
if(!objCheckBoxes)
return;
var countCheckBoxes = objCheckBoxes.length;
if(!countCheckBoxes)
objCheckBoxes.checked = CheckValue;
else
// set the check value for all check boxes
for(var i = 0; i < countCheckBoxes; i++)
objCheckBoxes[i].checked = CheckValue;
}
----------------- end Js ---------------------------- --------------