Javascript 使用默认值动态创建嵌套复选框在本地但在服务器上不起作用
您好,我正在尝试使用默认值动态创建嵌套复选框,它在本地系统上运行良好,但在服务器上运行不正常 HTML代码Javascript 使用默认值动态创建嵌套复选框在本地但在服务器上不起作用,javascript,php,jquery,html,checkbox,Javascript,Php,Jquery,Html,Checkbox,您好,我正在尝试使用默认值动态创建嵌套复选框,它在本地系统上运行良好,但在服务器上运行不正常 HTML代码 <div style="width:33%;float:left;"> <span class="label">BodyParts/Muscles</span> <div id="exerciseFilterList_1"></div> </div> <div style="width:3
<div style="width:33%;float:left;">
<span class="label">BodyParts/Muscles</span>
<div id="exerciseFilterList_1"></div>
</div>
<div style="width:33%;float:left;">
<span class="label">Goals (Objective)</span>
<div id="exerciseFilterList_2"></div>
</div>
<div style="width:33%;float:left;">
<span class="label">Device (Tools)</span>
<div id="exerciseFilterList_3"></div>
</div>
<div style="clear:both;"></div>
我已经动态生成了复选框,该复选框工作正常,但当我在加载时在复选框中填充数据时,它不工作。在加载getEditdata
函数时,在本地但在服务器上一切正常,复选框未选中
下面是本地和服务器的映像
您是否收到任何错误?没有,相同的代码但在服务器上不起作用。即使在控制台中也没有js错误。
function getExerciseFilter() {
$.getJSON("get_all_exercisefilter.php", function (dataAll) {
$('#exerciseFilterList_1').html(dataAll.filter_bodyParts_view);
$('#exerciseFilterList_2').html(dataAll.filter_goals_view);
$('#exerciseFilterList_3').html(dataAll.filter_tools_view);
});
}
/*----------
nested checkbox function*/
//nested checkbox function
$(document).on("change", "input[type='checkbox']", function (e) {
console.log('always');
var checked = $(this).prop("checked"),
container = $(this).parent(),
siblings = container.siblings();
container.find('input[type="checkbox"]').prop({
indeterminate: false,
checked: checked
});
function checkSiblings(el) {
var parent = el.parent().parent(),
all = true;
el.siblings().each(function () {
return all = $(this).children('input[type="checkbox"]').prop("checked") === checked);
});
if (all && checked) {
parent.children('input[type="checkbox"]').prop({
indeterminate: false,
checked: checked
});
checkSiblings(parent);
}
else if (all && !checked) {
parent.children('input[type="checkbox"]').prop("checked", checked);
parent.children('input[type="checkbox"]').prop("indeterminate", (parent.find('input[type="checkbox"]:checked').length > 0));
checkSiblings(parent);
}
else {
el.parents("li").children('input[type="checkbox"]').prop({
indeterminate: true,
checked: false
});
}
}
checkSiblings(container);
});
/*----------
function that fetch data onload*/
function getEditData() {
$.getJSON("get_exercise_by_id.php?cid=" + cid, function (data) {
data = data[0];
var myfilter = '';
if (typeof (data.filters) != "undefined" && data.filters !== null) {
myfilter = data.filters;
}
if (typeof (myfilter.body_parts) != "undefined" && myfilter.body_parts !== null) {
var pharse_id = ''
for (var body_parts = 0; body_parts < myfilter.body_parts.length; body_parts++) {
pharse_id = '#filter_' + myfilter.body_parts[body_parts];
$(pharse_id).attr('checked', 'checked');
}
}
if (typeof (myfilter.goals) != "undefined" && myfilter.goals !== null) {
var pharse_id = ''
for (var goals = 0; goals < myfilter.goals.length; goals++) {
pharse_id = '#filter_' + myfilter.goals[goals];
$('#filter_' + myfilter.goals[goals]).attr('checked', 'checked');
}
}
if (typeof (myfilter.tools) != "undefined" && myfilter.tools !== null) {
var pharse_id = ''
for (var tools = 0; tools < myfilter.tools.length; tools++) {
pharse_id = '#filter_' + myfilter.tools[tools];
$('#filter_' + myfilter.tools[tools]).attr('checked', 'checked');
}
}
}
[
{
"filters": {
"body_parts": [
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"11",
"12",
"13",
"14",
"98",
"99",
"100",
"111",
"112",
"113"
],
"goals": [
"120",
"121",
"122"
],
"tools": [
"133",
"134",
"135"
]
}
}
]