C# ajax调用后未设置样式的复选框
我有一个脚本文件scripts.js,其中有一个函数可以设置页面中所有复选框的样式。此文件在母版页中引用 它有一个用户控件和一个aspx测试页。在页面加载时,UC显示复选框列表,并应用样式 单击一个按钮,ajax调用将从数据库获取一个列表,并将更多复选框绑定到页面。但对于新复选框,不应用样式。可能出了什么问题 scripts.js: ctrl.ascx: 在页面上加载两个警报弹出窗口。但单击“显示更多”时,只有alert1弹出 浏览器控制台中没有错误 呈现的HTML:C# ajax调用后未设置样式的复选框,c#,asp.net,ajax,C#,Asp.net,Ajax,我有一个脚本文件scripts.js,其中有一个函数可以设置页面中所有复选框的样式。此文件在母版页中引用 它有一个用户控件和一个aspx测试页。在页面加载时,UC显示复选框列表,并应用样式 单击一个按钮,ajax调用将从数据库获取一个列表,并将更多复选框绑定到页面。但对于新复选框,不应用样式。可能出了什么问题 scripts.js: ctrl.ascx: 在页面上加载两个警报弹出窗口。但单击“显示更多”时,只有alert1弹出 浏览器控制台中没有错误 呈现的HTML: 我不明白为什么select
我不明白为什么selectcheckBtn中的if条件不正确;,对于新的chkboxes。因此,为复选框添加了一个新类,并编写了此解决方案。 现在调用此函数,而不是选择CheckBTN;在ajax代码中,这是有效的
function StyleCheckBox() {
$(".chkBx").each(function () {
if ($(this).prev("span").length === 0) {
$("<span class='uncheked'></span>").insertBefore($(this));
}
$("input:checkbox").click(function () {
check = $(this).is(":checked");
if (check) {
$(this).prev("span").addClass("cheked").removeClass("uncheked")
} else {
$(this).prev("span").addClass("uncheked").removeClass("cheked")
}
});
$("input:checked").prev("span").addClass("cheked").removeClass("uncheked")
});
}
你写了好几次“cheked”而不是“checked”,这可能是原因吗?不,不是。我敢肯定。这就是它在函数中的定义方式,它在页面加载中运行良好。
<script>
function ShowMore() {
$.ajax({
url: "/_layouts/15/handlers/ShowMore.ashx",
data: {},
success: function (msg) {
//append new chkbox list to existing list. It is hidden at first and later faded in.
$(".divList").append(msg);
selectcheckBtn();
$(".hideDiv").fadeIn(300).removeClass("hideDiv");
},
error: function (msg) {
alert("An error occurred while processing your request");
}
});
}
</script>
<a href="javascript:;" id="btnMore" runat="server" onclick="ShowMore();">Show more </a>
//with style applied to chkboxes on page load
<div><span class="uncheked"></span><input type="checkbox" runat="server" id="406">
<label>Compare</label></div>
//with no style applied to new chkboxes
<div><input type="checkbox" runat="server" id="618"><label>Compare</label></div>
function StyleCheckBox() {
$(".chkBx").each(function () {
if ($(this).prev("span").length === 0) {
$("<span class='uncheked'></span>").insertBefore($(this));
}
$("input:checkbox").click(function () {
check = $(this).is(":checked");
if (check) {
$(this).prev("span").addClass("cheked").removeClass("uncheked")
} else {
$(this).prev("span").addClass("uncheked").removeClass("cheked")
}
});
$("input:checked").prev("span").addClass("cheked").removeClass("uncheked")
});
}