我在jQuery 1.3.2上
我需要一个非常简单的代码。
我有4个复选框。
隐藏其中一个复选框。
我希望当单击3个可见复选框中的一个时,将自动检查隐藏的复选框。
所以我有
<input type="checkbox" style="display:none" id="hiddenOne"> <input type="checkbox" style="display:block" id="visible2"> <input type="checkbox" style="display:block" id="visible3"> <input type="checkbox" style="display:block" id="visible4">因此,如果我点击任何visible2 3或4,将自动检查hiddenOne。
有没有办法在jQuery中做到这一点?
谢谢!
I am on jQuery 1.3.2
I need a very simple code.
I have 4 checkboxes.
One of these checkboxes is hidden.
I want that when one of the 3 visible checkboxes is clicked the hidden one will be automatically checked.
So I have
<input type="checkbox" style="display:none" id="hiddenOne"> <input type="checkbox" style="display:block" id="visible2"> <input type="checkbox" style="display:block" id="visible3"> <input type="checkbox" style="display:block" id="visible4">So if I click on any visible2 3 or 4 the hiddenOne will be automatically checked.
Is there a way to do that in jQuery?
Thank you!
最满意答案
这将检查是否检查了三个可见的任何一个,如果有的则显示隐藏的那个并检查它。
http://jsfiddle.net/pxfunc/S6SFZ/
HTML:
<label id="hiddenLabel" style="display:none"><input type="checkbox" id="hiddenOne"> Hidden One</label> <label><input type="checkbox" id="visible2" class="visiChk"> Visible 2</label> <label><input type="checkbox" id="visible3" class="visiChk"> Visible 3</label> <label><input type="checkbox" id="visible4" class="visiChk"> Visible 4</label>jQuery的:
// update if any of the three are checked/unchecked $('.visiChk').change(function() { var hiddenOne = $('#hiddenLabel')[0]; // Are any of them checked ? if ($('.visiChk:checked').length > 0) { hiddenOne.style.display = 'block'; hiddenOne.checked = true; } else { hiddenOne.style.display = 'none'; hiddenOne.checked = false; } });this will check if any of the three visible's are checked, if any are then show the hidden one and check it.
http://jsfiddle.net/pxfunc/S6SFZ/
HTML:
<label id="hiddenLabel" style="display:none"><input type="checkbox" id="hiddenOne"> Hidden One</label> <label><input type="checkbox" id="visible2" class="visiChk"> Visible 2</label> <label><input type="checkbox" id="visible3" class="visiChk"> Visible 3</label> <label><input type="checkbox" id="visible4" class="visiChk"> Visible 4</label>jQuery:
// update if any of the three are checked/unchecked $('.visiChk').change(function() { var hiddenOne = $('#hiddenLabel')[0]; // Are any of them checked ? if ($('.visiChk:checked').length > 0) { hiddenOne.style.display = 'block'; hiddenOne.checked = true; } else { hiddenOne.style.display = 'none'; hiddenOne.checked = false; } });更多推荐
发布评论