Riveran
@Riveran
Astartes

Как изменить состояния всех чекбоксов?

есть колонка с чекбоксами
spoiler
5d0582c53e49a551113872.png

как сделать так, что бы при клике на самый первый чекбокс (в строке #) изменять состояния всех чекбоксов?
Код
html
<table class="table table-dark">
        <thead>
        <tr>
            <th scope="col">#</th>
            <td scope="col"><input id="main-checkbox" onclick="setCheckAll()" type="checkbox"></td>
            <th scope="col">DevEUI</th>
            <th scope="col">Dev description</th>
            <th scope="col">Number</th>
            <th scope="col">Status</th>
        </tr>
        </thead>
        <tbody id="results">
        </tbody>
    </table>

js
function setCheckAll() {

}

function displayLine(data) {
	$('#results').append(`
	<tr>
		<th scope="row">${importLines.length}</th>
			<td><input onclick='f(${JSON.stringify(data)})' type="checkbox"></td>
			<td>${data[0]}</td>
			<td>${data[2]}</td>
			<td>${data[11]}</td>
			<td id="status-${data[0]}"><b><span style="color: orange">PENDING</span></b></td>
		</tr>
`);
}
  • Вопрос задан
  • 112 просмотров
Решения вопроса 1
dollar
@dollar
Делай добро и бросай его в воду.
function setCheckAll() {
	let c;
	document.querySelectorAll('input[type=checkbox]').forEach(e=>{
		if (e.id=='main-checkbox') return (c=e.checked);
		e.checked=c;
	});
}
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы