在选中子复选框父不检查反之亦然完美的作品
on checking the child checkbox parent does not checked vise versa Works perfectly
您好,当我单击父复选框时,我在 asp.net repeater
中有这些复选框,正如您在此 picture 中看到的那样,所有子复选框都被选中,另一方面,当我选中时未选中父项的子项复选框。我正在使用 Jquery
来实现这一点
我当前的 ASP.NET
代码如下
<ul id='<%# "p_"+Eval("ApplicationId") %>' class="child-ul-hide child-ul">
<asp:Repeater ID="rptrPages" runat="server" OnItemDataBound="rptrPages_ItemDataBound">
<ItemTemplate>
<li>
<%-- <span id='<%# "sp_"+Eval("PageId") %>' class="parent arrow-right" state="hide"></span>--%>
<asp:Label ID="lblSpaces" runat="server" Text='<%# Eval("Spaces") %>'></asp:Label>
<asp:Literal ID="ltrArrowSpan" runat="server"></asp:Literal>
<label>
<asp:CheckBox ID="chkPage" runat="server" Text='<%# Eval("PageTitle") %>'
CssClass='<%# "page Pid_"+ Eval("ParentId")%>' PageId='<%# Eval("PageId") %>' ParentId='<%# Eval("ParentId") %>'
Checked='<%# Eval("IsEnable")== null ? false: Convert.ToBoolean(Eval("IsEnable").ToString()) %>' />
</label>
<asp:HiddenField ID="hdPageId" runat="server" Value='<%# Eval("PageId") %>' />
我的JavaScript
代码如下
如您所见,我尝试了一些其他的东西,也使用了 Intermediate snippiest,但是当他们被邀请 ASP.NET
时,一切都没有按计划进行。你们中的许多人可能会建议使用 <input type='checkbox'/>
抱歉我不能这样做
$(document).ready(function () {
/* Hide Show Tree lis
*******************************************/
$(".parent").click(function () {
var ID = $(this).attr("id");
var state = $("#" + ID).attr("state");
if (state == "hide") {
$("#" + ID).attr('state', 'show');
$("#" + ID).addClass("arrow-down").removeClass("arrow-right");
ID = ID.replace("s", "");
$("#" + ID).addClass("child-ul-show").removeClass("child-ul-hide");
}
else {
$("#" + ID).attr('state', 'hide');
$("#" + ID).addClass("arrow-right").removeClass("arrow-down");
ID = ID.replace("s", "");
$("#" + ID).addClass("child-ul-hide").removeClass("child-ul-show");
}
});
// /* START Parent Enable CheckBox Click Event
// *********************************************/
$(".page input[type='checkbox']").click(function() {
var PageId = $(this).parent('.page').attr("PageId");
var parentId = $(this).parent('.page').attr("ParentId");
var EnableStatus = $(this).prop("checked");
// Check/ Uncheck Controls Checkboxes
$("." + PageId + " input[type='checkbox']").prop('checked', EnableStatus);
//Check unCheck Childs Checkboxes
$(".Pid_" + PageId + " input[type='checkbox']").prop('checked', EnableStatus);
$(".Pid_" + PageId + " input[type='checkbox']").each(function() {
PageId = $(this).parent('.page').attr("PageId");
EnableStatus = $(this).prop("checked");
$(".Pid_" + PageId + " input[type='checkbox']").prop('checked', EnableStatus);
});
//$(".page input[type='checkbox']").prop('checked', false);
//$(".Pid_" + ParentId + " input[type='checkbox']").each(function() {
// debugger;
// EnableStatus = $(this).prop("checked");
// if (EnableStatus) {
// $(".page input[type='checkbox']").prop('checked', EnableStatus);
// return false;
// }
//});
debugger;
parentId = parseInt(parentId);
if (parentId>0) {
$("input[type='checkbox'][ParentId^='" + parentId + "']").prop('checked', true);
}
/*/ */
//$('input[name=' + parentId + '][value=Done][type=checkbox]:not(:checked)').attr({
// checked: 'checked',
// disabled: 'disabled'
//});
});
我看到的是您有一个复选框,它同时充当父项和子项,我不知道是什么让您这样做。
让我们找到答案。
将属性添加到 class 作为
ParentId='<%# Eval("ParentId")
获取该属性
var ParentId = $(this).parent('.page').attr("ParentId");
使用 JavaScript parseInt
将您的 id 解析为整数而不是这个
ParentId= parseInt(ParentId);
if (ParentId > 0) {
$(".p_" + ParentId + " input[type='checkbox']").prop('checked', false);
$(".Pid_" + ParentId + " input[type='checkbox']").each(function () {
EnableStatus = $(this).prop("checked");
if (EnableStatus)
{
$(".p_" + ParentId + " input[type='checkbox']").prop('checked', EnableStatus);
}
});
}
希望对您有所帮助
您好,当我单击父复选框时,我在 asp.net repeater
中有这些复选框,正如您在此 picture 中看到的那样,所有子复选框都被选中,另一方面,当我选中时未选中父项的子项复选框。我正在使用 Jquery
来实现这一点
我当前的 ASP.NET
代码如下
<ul id='<%# "p_"+Eval("ApplicationId") %>' class="child-ul-hide child-ul">
<asp:Repeater ID="rptrPages" runat="server" OnItemDataBound="rptrPages_ItemDataBound">
<ItemTemplate>
<li>
<%-- <span id='<%# "sp_"+Eval("PageId") %>' class="parent arrow-right" state="hide"></span>--%>
<asp:Label ID="lblSpaces" runat="server" Text='<%# Eval("Spaces") %>'></asp:Label>
<asp:Literal ID="ltrArrowSpan" runat="server"></asp:Literal>
<label>
<asp:CheckBox ID="chkPage" runat="server" Text='<%# Eval("PageTitle") %>'
CssClass='<%# "page Pid_"+ Eval("ParentId")%>' PageId='<%# Eval("PageId") %>' ParentId='<%# Eval("ParentId") %>'
Checked='<%# Eval("IsEnable")== null ? false: Convert.ToBoolean(Eval("IsEnable").ToString()) %>' />
</label>
<asp:HiddenField ID="hdPageId" runat="server" Value='<%# Eval("PageId") %>' />
我的JavaScript
代码如下
如您所见,我尝试了一些其他的东西,也使用了 Intermediate snippiest,但是当他们被邀请 ASP.NET
时,一切都没有按计划进行。你们中的许多人可能会建议使用 <input type='checkbox'/>
抱歉我不能这样做
$(document).ready(function () {
/* Hide Show Tree lis
*******************************************/
$(".parent").click(function () {
var ID = $(this).attr("id");
var state = $("#" + ID).attr("state");
if (state == "hide") {
$("#" + ID).attr('state', 'show');
$("#" + ID).addClass("arrow-down").removeClass("arrow-right");
ID = ID.replace("s", "");
$("#" + ID).addClass("child-ul-show").removeClass("child-ul-hide");
}
else {
$("#" + ID).attr('state', 'hide');
$("#" + ID).addClass("arrow-right").removeClass("arrow-down");
ID = ID.replace("s", "");
$("#" + ID).addClass("child-ul-hide").removeClass("child-ul-show");
}
});
// /* START Parent Enable CheckBox Click Event
// *********************************************/
$(".page input[type='checkbox']").click(function() {
var PageId = $(this).parent('.page').attr("PageId");
var parentId = $(this).parent('.page').attr("ParentId");
var EnableStatus = $(this).prop("checked");
// Check/ Uncheck Controls Checkboxes
$("." + PageId + " input[type='checkbox']").prop('checked', EnableStatus);
//Check unCheck Childs Checkboxes
$(".Pid_" + PageId + " input[type='checkbox']").prop('checked', EnableStatus);
$(".Pid_" + PageId + " input[type='checkbox']").each(function() {
PageId = $(this).parent('.page').attr("PageId");
EnableStatus = $(this).prop("checked");
$(".Pid_" + PageId + " input[type='checkbox']").prop('checked', EnableStatus);
});
//$(".page input[type='checkbox']").prop('checked', false);
//$(".Pid_" + ParentId + " input[type='checkbox']").each(function() {
// debugger;
// EnableStatus = $(this).prop("checked");
// if (EnableStatus) {
// $(".page input[type='checkbox']").prop('checked', EnableStatus);
// return false;
// }
//});
debugger;
parentId = parseInt(parentId);
if (parentId>0) {
$("input[type='checkbox'][ParentId^='" + parentId + "']").prop('checked', true);
}
/*/ */
//$('input[name=' + parentId + '][value=Done][type=checkbox]:not(:checked)').attr({
// checked: 'checked',
// disabled: 'disabled'
//});
});
我看到的是您有一个复选框,它同时充当父项和子项,我不知道是什么让您这样做。
让我们找到答案。
将属性添加到 class 作为
ParentId='<%# Eval("ParentId")
获取该属性
var ParentId = $(this).parent('.page').attr("ParentId");
使用 JavaScript parseInt
将您的 id 解析为整数而不是这个
ParentId= parseInt(ParentId);
if (ParentId > 0) {
$(".p_" + ParentId + " input[type='checkbox']").prop('checked', false);
$(".Pid_" + ParentId + " input[type='checkbox']").each(function () {
EnableStatus = $(this).prop("checked");
if (EnableStatus)
{
$(".p_" + ParentId + " input[type='checkbox']").prop('checked', EnableStatus);
}
});
}
希望对您有所帮助