I have a question, I need to create a checkbox that selects all, which is already running 100% but I can't create a "parent" checkbox that only marks his child checkboxes
enter code here
<input type="checkbox" title="todos" id="checkTodos" name="checkTodos"> <label><b>Marcar/Desmarcar Todos</b></label>
<div class="Registro">
<input type="checkbox" checked="checked" class="chkTela" />
<asp:HyperLink runat="server" ID="hlTela">
<span class="Tela">Tela <%#Eval("Descricao") %></span></asp:HyperLink>
<ul>
<asp:Repeater ID="rptTipoCritica" runat="server" OnItemCommand="rptTipoCriticas_ItemCommand">
<ItemTemplate>
<li>
<input name="chkCritica" id='chk<%#Eval("Codigo") %>' value='<%#Eval("Codigo") %>' type="checkbox" <%# EmAnalise && (Eval("Executada").ToString() == "False") ? "checked='checked' ": "disabled=disabled" %> />
<asp:Image ID="imgExecutada" runat="server" />
<asp:Button ID="btnVerificar" runat="server" Text="Verificar" CommandArgument='<%#Eval("Codigo") %>' CommandName="Verificar" />
<label for='chk<%#Eval("Codigo") %>'><%#Eval("Descricao") %></label></li>
</ItemTemplate>
</asp:Repeater>
</ul>
</div>
<script type="text/javascript">
$(function() {
$(".chkTela").on("click",
function() {
propagarSelecao($(this));
});
});
$("#checkTodos").change(function () {
$("input:checkbox").prop('checked', $(this).prop("checked"));
});
function propagarSelecao($chk) {
$("input[type=checkbox]:not(:disabled)", $chk.parent()).attr("checked", $chk.attr("checked"));
}
</script>
question from:
https://stackoverflow.com/questions/65845313/checkbox-child-parent-javascript 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…