_____ _____________
name | select all o
----- -------------
abcd | o
efcg | o
qwer | o
zxcv | o
-------------------
时当我点击选择所有复选框应该选择所有的复选框和相应的所有的值应使用JavaScript被存储在阵列[]在像[abcd,efch,qwer,zxcv]
。 在此先感谢得到检查框的值选择所有被点击
_____ _____________
name | select all o
----- -------------
abcd | o
efcg | o
qwer | o
zxcv | o
-------------------
时当我点击选择所有复选框应该选择所有的复选框和相应的所有的值应使用JavaScript被存储在阵列[]在像[abcd,efch,qwer,zxcv]
。 在此先感谢得到检查框的值选择所有被点击
选中复选框
function checkAll(ckbAll) {
var a[] = new array[50];
if (ckbAll.checked == true) {
$('input[type=checkbox]').each(function() {
$(this).attr('checked', 'checked');
a=$(this).val();
});
} else {
$('input[type=checkbox]').each(function() {
$(this).removeAttr('checked');
//do your logic to delete it from array
});
}
}
这个问题不清楚你怎么能回答它? – KarthikManoharan
@KarthikManoharan:OP希望js代码选择所有复选框,并取消选择所有,并且我提供了代码。并且答案不在可以投票的情况下 –
以下函数的所有代码应该由“平变化”的“全选”复选框的事件
例被称为:
<input type="checkbox" name="select_all" value="select_all" onchange="checkAll()">
function checkAll() {
var checkboxes = document.getElementsByClassName('class_name_of_all_checkboxes'); // You have to give this class name to all checkboxes you want to check
var checkbox_values = []; // If you need to access this array outside this function, then you will have to define it before the function
for (index = 0; index < checkboxes.length; ++index) {
if(!checkboxes[index].checked) {
checkboxes[index].checked = true;
checkbox_values.push(checkboxes[index].value);
}
}
}
哪里的代码..? [你有什么尝试..?](http://mattgemmell.com/what-have-you-tried/) –
显示你的尝试。 – Animesh
根据我的理解,你正在寻找这个 - http://jsfiddle.net/HVXSp/ –