admin管理员组文章数量:1405186
I have 6 checkboxes, one for each business day and one that says 'all'.
What i want to be able to do is uncheck all the other boxes if someone clicks the 'all' checkbox if that makes sense.
For example, if someone has clicked monday and wednesday ... then they e in and click the 'all' checkbox, then the monday and wednesday checkbox should uncheck.
Cheers,
I have 6 checkboxes, one for each business day and one that says 'all'.
What i want to be able to do is uncheck all the other boxes if someone clicks the 'all' checkbox if that makes sense.
For example, if someone has clicked monday and wednesday ... then they e in and click the 'all' checkbox, then the monday and wednesday checkbox should uncheck.
Cheers,
Share asked Dec 15, 2010 at 3:50 ChrisChris 1,1294 gold badges17 silver badges23 bronze badges 3-
Normally a user would check
all
when he wants to check all the checkboxes. Is this you want? – rahul Commented Dec 15, 2010 at 3:53 - I would do it that way .... but the people im doing it for want it the other way around, when the user clicks all, all the rest of the checkboxes uncheck except the all one. – Chris Commented Dec 15, 2010 at 3:55
- And which part are you having trouble with? Or should we just Give You Teh Codez? – Brad Mace Commented Dec 15, 2010 at 3:56
2 Answers
Reset to default 4This is not you want, but seems to be more sensible.
HTML
<input type="checkbox" id="chkAll" />
<br />
<input type="checkbox" id="chkMonday" class="child" />
<input type="checkbox" id="chkTuesday" class="child" />
<input type="checkbox" id="chkWednesday" class="child" />
<input type="checkbox" id="chkThursday" class="child" />
<input type="checkbox" id="chkFriday" class="child" />
<input type="checkbox" id="chkSaturday" class="child" />
<input type="checkbox" id="chkSunday" class="child" />
jQUery
$(function(){
$("#chkAll").change(function(){
if (this.checked) {
$("input:checkbox.child").attr("checked", "checked");
}
else {
$("input:checkbox.child").removeAttr("checked");
}
});
});
See a working demo
See an updated version which handles change in the child checkboxes also.
jquery and some code like this should do it.
$('#all-id').change(function(){
if($('#all-id').is(':checked')){
if($('#monday-id').is(':checked')){
$('#monday-id').attr('checked', false);
} else {
$('#monday-id').attr('checked', true);
}
// etc
}
});
After you might want to put all the ids in an array and setup a loop or play with the structure of your document to be able to easily loop on all of those checkboxes
本文标签: phpCheckbox onclick uncheck other checkboxesStack Overflow
版权声明:本文标题:php - Checkbox onclick uncheck other checkboxes - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744881055a2630207.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论