_____ _____________
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/ –