限制默认选中复选框 [英] Limiting Default Checked checkboxes
问题描述
我有关于我如何限制我的默认复选框的问题。
例如我有7个复选框。并且我想在页面加载后将其限制为3个默认复选框。
这应该是输出:
Checkbox1:true
Checkbox2:true
Checkbox3:true
Checkbox4:false
Checkbox5:false
Checkbox6:false
Checkbox7:false
以下是我的示例代码:
var mvp = 3;每个(函数(索引){
($ this).attr(checked),
$(document).ready(function(){
$ true);
});
});
我有这个,我不知道我会把我的柜台里面我的每个函数。在这段代码中,我所有的复选框都被选中:D。
对于新手问题,请帮助我..
实际上不需要计数器,因为每个
函数都会在索引中传递。只需使用索引作为计数器。
$(document).ready(function(){
$输入:checkbox)。每个(函数(索引){
this.checked =(index< 3);
});
}
JS Fiddle: http://jsfiddle.net/SB6aD/2/
I have problem regarding on how i will limit my default checked checkbox. for example i have 7 checkboxes. and i want to limit it with 3 default checked checkboxes once the page is load.
this should be the output:
Checkbox1 : true
Checkbox2 : true
Checkbox3 : true
Checkbox4 : false
Checkbox5 : false
Checkbox6 : false
Checkbox7 : false
Here's my sample code:
var mvp = 3;
$(document).ready(function() {
$("input:checkbox").each(function( index ) {
($this).attr("checked",true);
});
});
I'm stock with this, i don't know where i will put my counter (mvp) inside my each function. in this code, all my checkboxes are checked :D.
Sorry for a newbie question, please help me..
There is actual no need for a counter since the each
function will pass in the index. Just use the index as the counter.
$(document).ready(function() {
$("input:checkbox").each(function( index ) {
this.checked = (index < 3);
});
});
JS Fiddle: http://jsfiddle.net/SB6aD/2/
这篇关于限制默认选中复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!