[英]Show/hide based on checkbox
我有代碼來查看是否選中了任何復選框,它正在工作。 這就是我確定的地方,在它看到沒有被選中之后,檢查了我想讓一個 DIV 出現(我猜是隱藏/顯示)某個地方,如果選中了任何一個框,它就會消失。
function checkBoxValidate(cb) {
for (j = 0; j < 8; j++) {
if (eval("document.myform.checkbox[" + j + "].checked") = false) {
document.views.checkbox[j].checked = false;
}
}
}
----------
<form name="myform">
<input class="checkbox" name="1" type="checkbox" value="check_1" onclick="document.getElementById('r-click').innerHTML = '1;" id="click">
1
<input class="checkbox" name="2" type="checkbox" value="check_2" onclick="document.getElementById('s-click').innerHTML = '2';" id="click">
2
</form>
<div id=showInstructions>Check boxes</div>
謝謝!
在您的原始代碼中添加了幾行代碼來演示:
(順便說一句,整個“評估”的東西有點亂,可以寫得更簡單......)
function checkBoxValidate(cb) {
var somethingIsChecked = false;
for (j = 0; j < 8; j++) {
if (eval("document.myform.checkbox[" + j + "].checked") = false) {
document.views.checkbox[j].checked = false;
}
else {
somethingIsChecked = true;
}
if (somethingIsChecked)
document.getElementById("showInstructions").style.display = "block";
else
document.getElementById("showInstructions").style.display = "none";
function checkBoxValidate(cb) {
var noneChecked = true;
for (j = 0; j < 8; j++) {
if (eval("document.myform.checkbox[" + j + "].checked") == false) {
document.views.checkbox[j].checked = false;
} else {
noneChecked = false;
}
}
document.getElementById("showInstructions").style.display = noneChecked ? "block" : "none";
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.