Clicking input has no effect, why?
I want the effect to be that either clicking on the line or the input can be applied to the input.
var trs = document.getElementsByTagName('tr')
var control = true
for (var i = 0; i < trs.length; i++) {
trs[i].onclick = function() {
if (this.getElementsByTagName('input')[0].checked == true) {
this.getElementsByTagName('input')[0].checked = false
} else if (this.getElementsByTagName('input')[0].checked == false) {
this.getElementsByTagName('input')[0].checked = true
}
}
trs[i].onmouseenter = function() {
this.style.backgroundColor = 'grey'
}
trs[i].onmouseleave = function() {
this.style.backgroundColor = ''
}
}
table {
border: 1px solid black;
border-collapse: collapse;
width: 60%;
}
td {
border: 1px solid black;
text-align: center;
}
<table>
<thead>
<tr>
<td><input type="Checkbox">全选</td>
<td>商品</td>
</tr>
</thead>
<tbody>
<tr>
<td><input type="Checkbox"></td>
<td>手机</td>
</tr>
<tr>
<td><input type="Checkbox"></td>
<td>电脑</td>
</tr>
<tr>
<td><input type="Checkbox"></td>
<td>手表</td>
</tr>
<tr>
<td><input type="Checkbox"></td>
<td>耳机</td>
</tr>
</tbody>
<input type="Checkbox">
</table>