复选框子父JavaScript
我有一个问题,我需要创建一个复选框,选择所有,这已经是100%运行,但我不能创建一个“家长”复选框,只标记他的孩子复选框复选框子父JavaScript,javascript,c#,Javascript,C#,我有一个问题,我需要创建一个复选框,选择所有,这已经是100%运行,但我不能创建一个“家长”复选框,只标记他的孩子复选框 enter code here <input type="checkbox" title="todos" id="checkTodos" name="checkTodos"> <label><b>Marcar/Desmarcar Todos</b>
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>
在此处输入代码
马卡尔/德斯马尔·托多斯
影视处
-
$(函数(){
$(“.chkTela”)。点击,
函数(){
propagarSelecao($(本));
});
});
$(“#checkTodos”).change(函数(){
$(“输入:复选框”).prop('checked',$(this.prop(“checked”));
});
propagarSelecao功能($chk){
$($input[type=checkbox]:not(:disabled)”,$chk.parent()).attr(“选中”),$chk.attr(“选中”);
}
它看起来像这样吗
$(function () {
$('input:checkbox.main-checkbox').click(function () {
var array = [];
var parent = $(this).closest('.main-parent');
//check or uncheck sub-checkbox
$(parent).find('.sub-checkbox').prop("checked", $(this).prop("checked"))
//push checked sub-checkbox value to array
$(parent).find('.sub-checkbox:checked').each(function () {
array.push($(this).val());
})
});
})我设法解决了它!
下面是JQuery代码
$('input:checkbox.parent').click(function () {
if (this.checked) {
$(this).parents('li').children('input[type=checkbox]').prop('checked', true);
}
$(this).parent().find('input[type=checkbox]').prop('checked', this.checked);
});
我是否正确理解您的问题:如果选择了家长,您想选择所有孩子@AbbasAkhundov没错,我的复选框100%起作用,但我需要复选框“爸爸”不起作用,你有其他想法吗?