【发布时间】:2012-01-30 14:51:25
【问题描述】:
这是我的问题...我有一个加载客户列表的页面,点击那里的名称会弹出一个弹出窗口,您可以定义允许他们登录的时间,这里是 html 代码。
<form action="" method="post" name="access_hours">
<table width="100%">
<tr>
<td colspan="5">
<input type="checkbox" id="all" name="107" /> Check/Uncheck all
</td>
</tr>
<div id="check_107">
<tr>
<td><input type="checkbox" name="accesstimes[]" id="107" value="01" />1AM</td>
<td><input type="checkbox" name="accesstimes[]" id="107" value="02" /> 2AM</td>
<td><input type="checkbox" name="accesstimes[]" id="107" value="03" /> 3AM</td>
<td><input type="checkbox" name="accesstimes[]" id="107" value="04" /> 4AM</td>
<td><input type="checkbox" name="accesstimes[]" id="107" value="05" /> 5AM</td>
</tr>
<tr>
<td><input type="checkbox" name="accesstimes[]" id="107" value="06" /> 6AM</td>
<td><input type="checkbox" name="accesstimes[]" id="107" value="07" /> 7AM</td>
<td><input type="checkbox" name="accesstimes[]" id="107" value="08" /> 8AM</td>
<td><input type="checkbox" name="accesstimes[]" id="107" value="09" /> 9AM</td>
<td><input type="checkbox" name="accesstimes[]" id="107" value="10" />10AM</td>
</tr>
<tr>
<td><input type="checkbox" name="accesstimes[]" id="107" value="11" />11AM</td>
<td><input type="checkbox" name="accesstimes[]" id="107" value="12" />12PM</td>
<td><input type="checkbox" name="accesstimes[]" id="107" value="13" /> 1PM</td>
<td><input type="checkbox" name="accesstimes[]" id="107" value="14" /> 2PM</td>
<td><input type="checkbox" name="accesstimes[]" id="107" value="15" /> 3PM</td>
</tr>
<tr>
<td><input type="checkbox" name="accesstimes[]" id="107" value="16" /> 4PM</td>
<td><input type="checkbox" name="accesstimes[]" id="107" value="17" /> 5PM</td>
<td><input type="checkbox" name="accesstimes[]" id="107" value="18" /> 6PM</td>
<td><input type="checkbox" name="accesstimes[]" id="107" value="19" /> 7PM</td>
<td><input type="checkbox" name="accesstimes[]" id="107" value="20" /> 8PM</td>
</tr>
<tr>
<td><input type="checkbox" name="accesstimes[]" id="107" value="21" /> 9PM</td>
<td><input type="checkbox" name="accesstimes[]" id="107" value="22" />10PM</td>
<td><input type="checkbox" name="accesstimes[]" id="107" value="23" />11PM</td>
<td><input type="checkbox" name="accesstimes[]" id="107" value="00" />12AM</td>
<td><input type="checkbox" name="accesstimes[]" id="107" value="NONE" />NONE</td>
<td> </td>
</tr>
</div>
<td colspan="5">
<input type="hidden" name="id" value="107" />
<input type="submit" class="updatebutton" name="confirm" value="Update" />
</td></tr></table>
</form>
</div>
问题是,由于 jquery 弹出窗口,页面上大约有 10 组这些块,它们都位于 id 为“check_(idofblock)”的 div 下,这不是问题。我有选中/取消选中所有框工作。现在我似乎无法弄清楚,我如何得到它,所以当任何复选框被选中时,如果我点击标记为“NONE”的那个,那么这是唯一一个被选中的,如果没有被选中,我该怎么做单击其他任何内容后取消选中它?我似乎无法做到正确。这是我的“检查/取消检查所有”代码,它检查除 NONE 之外的所有内容。
$('input[id=all]').click(function() {
the_id = $(this).attr('name');
$('input:checkbox[id="'+the_id+'"]').attr('checked', ($(this).is(':checked')));
$('input:checkbox[id="'+the_id+'"][value="NONE"]').attr('checked', false);
});
我没有任何代码可以发布我需要的东西,因为它让我绞尽脑汁,所以我删除了它,并想我会问这里的每个人谁比我更聪明。
任何帮助将不胜感激:)
【问题讨论】:
-
ID 在页面上必须是唯一的,相关复选框需要使用 class 而不是 id。
标签: php jquery mysql html checkbox