Javascript和HTML问题 [英] Javascript and HTML problem
问题描述
我打算创建一个时钟,显示每个时间段的活动时间。问题是用户应该能够选择一个时间表,但不会列出相应的时间表,而是泄漏其他时间段。
代码 - Pastebin.com [ ^ ]
I am planning to create a clock that will show when each period of time is active. The problem is that the user is supposed to be able to select a schedule, but instead of listing that respective schedule, it leaks other periods.
Code - Pastebin.com[^]
<style>
.inv {
display:none;
}
p {
margin:0;
}
</style>
<input type="checkbox" id="Timea">Time Set (a)
<br>
<input type="checkbox" id="Timeb">Time Set (b)
<br>
<input type="button" value="Go" onClick="checkMode()">
<p id="Aa">1a</p> <!--for b,c-->
<p id="Ab">2a</p> <!--for b,c-->
<p id="Ac">3a</p>
<p id="Ad">4a</p>
<p id="Ae">3a</p>
<p id="Af">4a</p>
<p id="Ag">5a</p>
<p id="Ah">6a</p>
<p id="Ai">7a</p>
<p id="Aj">8a</p>
<p id="Ak">1a</p>
<p id="Al">2a</p>
<p id="Ba">8b</p>
<p id="Bb">7b</p>
<p id="Bc">6b</p>
<p id="Bd">5b</p>
<p id="Be">3b</p>
<p id="Bf">4b</p>
<p id="Bg">5b</p>
<p id="Bh">6b</p>
<p id="Bi">7b</p>
<p id="Bj">8b</p>
<p id="Bk">1b</p> <!--for a,c-->
<p id="Bl">2b</p> <!--for a,c-->
<p id="Ca">1c</p>
<p id="Cb">2c</p>
<p id="Cc">PTc</p>
<p id="Cd">3c</p>
<p id="Ce">4c</p>
<p id="Cf">5c</p>
<p id="Cg">6c</p>
<p id="Ch">7c</p>
<p id="Ci">8c</p>
<script>
function checkMode() {
var Ma = ["Aa","Ab","Ac","Ad","Ae","Af","Ag","Ah","Ai","Aj","Ak","Al"]
var Mb = ["Ba","Bb","Bc","Bd","Be","Bf","Bg","Bh","Bi","Bj","Bk","Bl"]
var Mc = ["Ca","Cb","Cc","Cd","Ce","Cf","Cg","Ch","Ci"]
var Pa = document.getElementById("Timea").checked;
var Pb = document.getElementById("Timeb").checked;
var mode = 0;
if (Pa == true) {
for (i=0;i<=Ma.length;i++) {
document.getElementById(Ma[i]).className = "";
document.getElementById(Mb[i]).className = "inv";
document.getElementById(Mc[i]).className = "inv";
}
} else if (Pb == true) {
for (i=0;i<=Mb.length;i++) {
document.getElementById(Ma[i]).className = "inv";
document.getElementById(Mb[i]).className = "";
document.getElementById(Mc[i]).className = "inv";
}
} else if (Pa == false && Pb == false) {
for (i=0;i<=Mc.length;i++) {
document.getElementById(Ma[i]).className = "inv";
document.getElementById(Mb[i]).className = "inv";
document.getElementById(Mc[i]).className = "";
}
}
}
</script>
我尝试了什么:
我已多次检查段落和数组之间的关系,但找不到问题仍然没有成功。
What I have tried:
I have checked the relation between the paragraphs and the arrays multiple times, but there still has been no success in finding the problem.
推荐答案
for (i=0;i<=Mc.length;i++)
你有一个问题,你在所有三个测试中都搜索了数组的末尾。
如果一个数组在javaScript(和几乎任何语言)中,长度为'len',您可以测试最多< len NOT < = len 的所有成员。数组元素[len]不存在。
You have a problem in that you're search past the end of the array in all three of your tests.
If an array in javaScript (and almost any language) has a length of 'len' you test all of the members with up to <len NOT <=len. Array element [len] does not exist.
这篇关于Javascript和HTML问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!