伙计们我试图在开关按钮之间建立关系。每个按钮代表一个设备。例如,如果我关闭x设备,它将关闭y和z。但如果y关闭,它会变得更多。我尝试使用switch case语句,但我的代码变得混乱。我试图找到是否是一个JavaScript库但没有结果。有什么想法吗?
function hm1() {
var hlektro1 = document.getElementById("device_engine1").checked;
switch (hlektro1) {
case (hlektro1 = true):
document.getElementById("device_x").checked = false;
document.getElementById("device_1").checked = false;
document.getElementById("device_NAUTICAL").checked = false;
document.getElementById("device_2").checked = false;
break
case (hlektro1 = false):
document.getElementById("device_x").checked = true;
document.getElementById("device_1").checked = true;
document.getElementById("device_NAUTICAL").checked = true;
document.getElementById("device_2").checked = true;
break
}
}
function gps() {
var gpsdevice = document.getElementById("device_x").checked;
switch (gpsdevice) {
case (gpsdevice = true):
document.getElementById("device_55").checked = false;
document.getElementById("device_123").checked = false;
document.getElementById("device_NAUTICAL").checked = false;
document.getElementById("device_CAMERA").checked = false;
document.getElementById("device_14").checked = false;
break
case (gpsdevice = false):
document.getElementById("device_55").checked = true;
document.getElementById("device_123").checked = true;
document.getElementById("device_NAUTICAL").checked = true;
document.getElementById("device_CAMERA").checked = true;
document.getElementById("device_14").checked = true;
break
}
}
开关按钮示例:
<div class="onoffswitch">
<input type="checkbox" name="engine1" class="onoffswitch-checkbox" id="device_Ηλεκτρομηχανη1" checked>
<label class="onoffswitch-label" for="device_engine1" onclick="hm1()">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>
答案 0 :(得分:0)
将for (int i = 0; i < articles.length(); i++) {
static {
addItem(new JsonParserItem("1", R.drawable.p1, "asd", "Steve Jobs", "Focusing is about saying No."));
}
}
添加到所有dependend复选框id
然后在“控制”复选框的class
上获取所有dependend复选框并相应地设置change
状态。
这样的事情:
checked
document.querySelector("#control").addEventListener("change", function(e) {
var checkbox = e.target,
dependendCheckboxes = document.querySelectorAll("." + checkbox.id);
for (var i = 0; i < dependendCheckboxes.length; i++) {
dependendCheckboxes[i].checked = checkbox.checked;
}
});