根据父checkbox的选中与取消,同时改变子checkbox
$(document).ready(function(){
$(".channel").each(function(){
$(this).change(function(){
var checked = $(this).attr("checked")
var value = $(this).val();
if(checked==undefined || checked != "checked"){
$(this).attr("checked","checked");
checked = "true";
}else{
$(this).removeAttr("checked");
checked = "false";
}
//根据父checkbox获取子checkbox
if(checked != "false")
{
$.ajax({
type: "POST",
url: "querySub.do?value="+value,
data: "value",
dataType: "json",
success: function(msg){
if(msg.length!=0){
/* for(var i=0; i<msg.length; i++){
alert(document.getElementsByName("subChannel"+msg[i].status)[i].checked)
document.getElementsByName("subChannel"+msg[i].status)[i].checked = true;
} */
for(var i=0;i<msg.length;i++){
html="<tr id='child"+msg[i].status+"'><td><input type='checkbox' checked />"+msg[i].description+" </td></tr>";
$("#childChannel").append(html);
}
}
}
});
}else{
// 取消时移除子checkbox
$.ajax({
type: "POST",
url: "querySub.do?value="+value,
data: "value",
dataType: "json",
success: function(msg){
if(msg.length!=0){
for(var i=0; i<msg.length; i++){
/* alert( document.getElementsByName("subChannel"+msg[i].status)[i])
document.getElementsByName("subChannel"+msg[i].status)[i].checked = false; */
$("#child"+msg[i].status+"").remove();
}
}
}
});
}
});});