我知道我的问题标题令人困惑,但我会尝试在这里解释所有内容。请先看我的代码:
<!DOCTYPE HTML>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
<input type="checkbox" class="check" id="firstCheck" onclick="myFunction();"> First<br>
<input type="checkbox" class="check" id="secondCheck" onclick="myFunction1();"> Second <br>
<input type="checkbox" id="new"> A <br>
<input type="checkbox" id="new1"> B <br>
</body>
<script>
function myFunction() {
var checkBox = document.getElementById("firstCheck");
//var text = document.getElementById("text");
if (checkBox.checked == true){
//text.style.display = "block";
document.getElementById("new").checked = true;
}
else if (checkBox.checked == false){
document.getElementById("new").checked = false;
}
else {
text.style.display = "none";
}
}
function myFunction1(){
var checkBox = document.getElementById("secondCheck");
//var text = document.getElementById("text");
if (checkBox.checked == true){
//text.style.display = "block";
document.getElementById("new1").checked = true;
}
else if (checkBox.checked == false){
document.getElementById("new1").checked = false;
}
else {
text.style.display = "none";
}
我在这里做的是当我选择/取消选择复选框时,首先它会自动选择/取消选择复选框 A,类似地,当我选择/取消选择复选框时,它会自动选择/取消选择复选框 B。我使用了代码,因此第一个或第二个复选框将是检查一次而不是两者。因此,当我选择复选框 First 时,它选择复选框 A,当我选择复选框 Second 而不取消选中 First 时,A 和 B 都被选中。当我再次选择 First 而没有取消选择 Second 时,A 和 B 都保持选中状态。这不是我想要的。我希望当有人检查 First 然后 A 应该被选中,这是现在发生的,但是当有人选择 Second 时,A 的复选框应该被取消选中,就像 checkbox first 被取消选中一样。我想让它像这样的形式:[网站:]https://www.swiftcomarine.com.au/BOAT-PACKAGE-SPECIALS-X15.html
您可以在网站的右侧看到,当有人检查标准包时,它会在它下方自动选择某些复选框以及检查其他复选框时,会自动选择其他复选框,并将先前未选中的复选框。这就是我想要的形式。请在这方面帮助我。谢谢
蛊毒传说
相关分类