我有一个HTML复选框的简单列表,如下所示:
<input type="button" class="check" value="check all" onclick="foo()"/>
<input type="checkbox" class="chk" value="1"/> Checkbox 1
<input type="checkbox" class="chk" value="2"/> Checkbox 2
<input type="checkbox" class="chk" value="3"/> Checkbox 3在单击"Check All“按钮时,我想编写一个ExtJS函数,它选择所有复选框(并再次切换它,取消所有复选框),并返回数组中选定的值。我已经使用jQuery完成了它,但是需要使用ExtJS编写它,我是非常新的。
发布于 2013-06-09 10:46:49
Ext.select('.chk').each(function(el) {
el.dom.checked = true;
});发布于 2013-07-16 14:59:30
HTML:
<div>
<label for="check">
<input type="checkbox" class="check" value="Toggle all" id="check" />
Toggle All
</label>
</div>
<div>
<label for="chk1">
<input type="checkbox" class="chk" id="chk1" value="1" />
Checkbox 1
</label>
<label for="chk2">
<input type="checkbox" class="chk" id="chk2" value="2" />
Checkbox 2
</label>
<label for="chk1">
<input type="checkbox" class="chk" id="chk3" value="3" />
Checkbox 3
</label>
</div>联署材料:
document.getElementById('check').onclick = function() {
var me = this;
var out = [];
Ext.select('.chk').each(function(el) {
el.dom.checked = me.checked;
if (me.checked) out.push(el.dom.value);
});
console.log(out);
};见行动:
http://jsfiddle.net/GeoForce/Er2JF/1/
发布于 2013-07-21 11:14:27
另一种解决办法是:
标记:
<input id="toggle" type="checkbox" name="toggle" value="true"><br />
<input class="chk" type="checkbox" name="chk[]" value="1"><br />
<input class="chk" type="checkbox" name="chk[]" value="2"><br />
<input class="chk" type="checkbox" name="chk[]" value="3">联署材料:
document.getElementById('toggle').onclick = function() {
var isChecked = false;
if (this.checked) isChecked = true;
Ext.select('.chk').each(function(el) {
el.dom.checked = isChecked;
});
};JsFiddle:http://jsfiddle.net/rayphi/ZeTvX/
https://stackoverflow.com/questions/17008479
复制相似问题