检查复选框是否检查,然后选中另一个复选框
我有一个网页上有6个复选框。
I have a web page which has 6 checkboxes on it.
<input type="checkbox" name="chk1" id="chk1" class="chkbox"/>
<input type="checkbox" name="chk2" id="chk2" class="chkbox"/>
<input type="checkbox" name="chk3" id="chk3" class="chkbox"/>
<input type="checkbox" name="chk4" id="chk4" class="chkbox"/>
<input type="checkbox" name="chk5" id="chk5" class="chkbox"/>
<input type="checkbox" name="chk6" id="chk6" class="chkbox"/>
使用jquery如何检查所有这6个复选框是否被选中,如果所有6复选框7:
Using jquery how can I check to see if all of these 6 checkboxes are checked and if all 6 are checked check checkbox number 7:
<input type="checkbox" name="chk7" id="chk7" class="chkbox"/>
我已经开始写函数,但不确定这是否是最好的方法: / p>
I have started to write the function but not sure if this is the best way to do this:
function AllSectionsChecked {
var isChecked1 = $('##chk1').attr('checked')?true:false;
var isChecked2 = $('##chk2').attr('checked')?true:false;
var isChecked3 = $('##chk3').attr('checked')?true:false;
var isChecked4 = $('##chk4').attr('checked')?true:false;
var isChecked5 = $('##chk5').attr('checked')?true:false;
var isChecked6 = $('##chk6').attr('checked')?true:false;
}
任何帮助将不胜感激。
Any help would be appreciated. I am guessing its pretty much straight forward but just looking for the best way to accomplish this in jquery.
更新:
* ID和名称是动态创建的,可能不是任何顺序或规模,所以一个id可能chk51和下一个也许chk205,Appologies我应该把这个在我原来的帖子*
Thankyou您的建议到目前为止。
UPDATE: *The ids and names are created dynaically and may not be in any order or scale so an id maybe chk51 and the next one maybe chk205, Appologies I should have put this in my original post * Thankyou for your suggestions so far.
非常感谢。
假设最后一个复选框的ID chk7
而不是 chk5
?
Assuming the ID of the last checkbox should be chk7
and not chk5
?
$('#chk7').prop('checked', $('input[type="checkbox"]:lt(6):checked').length == 6);