У меня есть стол. Элементы в thead содержат один флажок. Если я нажмем флажок "selectAll", он проверит все флажки в таблице. Мне пришлось добавить jquery tablesorter. Для этого мне пришлось использовать thead
. Мой javascript прекратил работать из-за thead. Если я удалю его, он будет работать нормально, и при щелчке по галочке проверьте все остальные флажки в таблице.
Мой html:
<thead>
<tr>
<th id="idCheckBox"><input type="checkbox" id="selectAll"/> All</th>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
<th id="idEsc">Column 4</th>
<th>Column 5</th>
<th id="idComments">Column 6</th>
<th id="idSuspend">Column 7</th>
</tr>
</thead>
Моя функция java-скрипта:
$( function() {
// add multiple select / deselect functionality
$("#selectAll").click( function() {
$('.case').attr('checked', this.checked);
});
$(".case").click( function() {
if ($(".case").length == $(".case:checked").length) {
$("#selectAll").attr("checked", "checked");
} else {
$("#selectAll").removeAttr("checked");
}
});
});
Любые гуру там для помощи?
ура
Я исправил проблему, добавив имя функции в javascript и позвонив в onclick
event of checkbox.
Мой html:
<th id="idCheckBox"><input type="checkbox" id="selectAll" onclick="selectCheckBoxes()"/> All</th>
и java-скрипт:
function selectCheckBoxes(){
// add multiple select / deselect functionality
$("#selectAll").click( function() {
$('.case').attr('checked', this.checked);
});
$(".case").click( function() {
if ($(".case").length == $(".case:checked").length) {
$("#selectAll").attr("checked", "checked");
} else {
$("#selectAll").removeAttr("checked");
}
});
};
Я не думаю, что это из - за thead
. Используйте .prop(), чтобы установить значение проверенного свойства
$(function () {
// add multiple select / deselect functionality
$("#selectAll").click(function () {
$cases.prop('checked', this.checked);
});
var $cases = $(".case").click(function () {
$("#selectAll").prop("checked", $cases.not(':checked').length == 0);
});
});
Демо: скрипка
thead
, используйте.prop()
чтобы установить проверенное свойство