以下是我的代码,第一次点击会获得一些复选框列表,然后点击每个复选框应触发第二次点击功能,使复选框列表动态刷新,并根据已检查的内容列出项目。第一次单击功能正常工作并获取所有复选框列表,但第二次单击只是在单击复选框时不会执行...我感觉到那里有一些愚蠢的错误,但不知道它会在哪里....
// functions to capture the selection of the template sidebar
$(function ()
{
$('.sidebar li > a').on('click', function (e)
{
var children = $(this).parent('li').find(' > ul > li');
if (children.length == 0)
{
var templateName = children.context.id;
$.ajax({
type: "Post",
url: "SingleViewNew2.aspx/AddParametersToSidebar",
contentType: "application/json",
dataType: "json",
data: "{theTemplateName:'" + templateName + "'}",
success: function (data) //callback function, VIF!! all the follow up content js should be included in this
{
// once in the template, 1,beautify the scroll bar 2,click checkbox or radio 3,launch report
//1
var item = data.d;
var sidebar = $('#right-sidebar');
sidebar[0].innerHTML = item;
$('.param_list').niceScroll({ cursorcolor: "##061B58" });
//2
},
error: function (err) { alert("oh no"); }
});
}
else if (children.is(":visible"))
{
children.hide('fast');
} else
{
children.show('fast');
}
e.stopPropagation();
});
$(":checkbox").click(function ()
{
var checkThisItem = $(this);
if (checkThisItem.checked == null)
{
checkThisItem.checked = false;
}
else
checkThisItem.checked = true;
// here get all the current checked items and then send them back to diplay the dependencyva
//var allItems = $("input");
var allCheckedItem = $(":checked:checked");
var passAllCheckedItem = new Array();
for (var i = 0; i < allCheckedItem.length; i++)
{
passAllCheckedItem[i] = allCheckedItem[i].name + "__" + allCheckedItem[i].defaultValue;
}
passAllCheckedItem = JSON.stringify(passAllCheckedItem);
$.ajax(
{
type: "Post",
url: "SingleViewNew2.aspx/updateParametersToSidebar",
contentType: "application/json",
traditional: true,
dataType: "json",
data: "{allCheckedItems :'" + passAllCheckedItem + "'}",
error: function (err) { alert("oh no"); },
success:function(data)
{
var item = data.d;
var sidebar = $('#right-sidebar');
sidebar[0].innerHTML = item;
$('.param_list').niceScroll({ cursorcolor: "##061B58" });
},
});
});
})