gpt4 book ai didi

Javascript - 加载当前月份 htm - 问题

转载 作者:太空宇宙 更新时间:2023-11-04 01:38:09 25 4
gpt4 key购买 nike

我在使用以下代码时遇到问题,总是想加载 2 月份的页面而不是当前月份的页面。我没有看到任何问题,但希望有更好的 javascript 眼睛的人可以提供帮助。

基本上,代码非常简单。在页面加载时获取当前月份,然后将该月份的 .htm 加载到框架中。十分简单。在此先感谢您提供的任何/所有帮助。

<!DOCTYPE html>
<html>

<head>
<meta http-equiv="refresh" content="60" />
<style>
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}

li {
float: left;
font-family: tahoma;
}

li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}

li a:hover {
background-color: #111;
}

#title {
background-color: #333;
border-right: 1px black dotted;
}

iframe {
width: 100%;
height: 1200px;
}
</style>

<script type="text/javascript">
window.onload = function() {
function cMonth() {
var d = new Date();
var q = d.getMonth();
}

function jan() {
document.querySelector(".sched").setAttribute("src", "jan.htm")
}

function feb() {
document.querySelector(".sched").setAttribute("src", "feb.htm")
}

function mar() {
document.querySelector(".sched").setAttribute("src", "mar.htm")
}

function apr() {
document.querySelector(".sched").setAttribute("src", "apr.htm")
}

function may() {
document.querySelector(".sched").setAttribute("src", "may.htm")
}

function jun() {
document.querySelector(".sched").setAttribute("src", "jun.htm")
}

function jul() {
document.querySelector(".sched").setAttribute("src", "jul.htm")
}

function aug() {
document.querySelector(".sched").setAttribute("src", "aug.htm")
}

function sep() {
document.querySelector(".sched").setAttribute("src", "sep.htm")
}

function oct() {
document.querySelector(".sched").setAttribute("src", "oct.htm")
}

function nov() {
document.querySelector(".sched").setAttribute("src", "nov.htm")
}

function dec() {
document.querySelector(".sched").setAttribute("src", "dec.htm")
}

document.getElementsByTagName("a")[1].onclick = jan;
document.getElementsByTagName("a")[2].onclick = feb;
document.getElementsByTagName("a")[3].onclick = mar;
document.getElementsByTagName("a")[4].onclick = apr;
document.getElementsByTagName("a")[5].onclick = may;
document.getElementsByTagName("a")[6].onclick = jun;
document.getElementsByTagName("a")[7].onclick = jul;
document.getElementsByTagName("a")[8].onclick = aug;
document.getElementsByTagName("a")[9].onclick = sep;
document.getElementsByTagName("a")[10].onclick = oct;
document.getElementsByTagName("a")[11].onclick = nov;
document.getElementsByTagName("a")[12].onclick = dec;

if (q = 0) {
document.getElementById('january').click() = jan;
} else if (q = 1) {
document.getElementById('february').click() = feb;
} else if (q = 2) {
document.getElementById('march').click() = mar;
} else if (q = 3) {
document.getElementById('april').click() = apr;
} else if (q = 4) {
document.getElementById('may').click() = may;
} else if (q = 5) {
document.getElementById('june').click() = jun;
} else if (q = 6) {
document.getElementById('july').click() = jul;
} else if (q = 7) {
document.getElementById('august').click() = aug;
} else if (q = 8) {
document.getElementById('september').click() = sep;
} else if (q = 9) {
document.getElementById('october').click() = oct;
} else if (q = 10) {
document.getElementById('november').click() = nov;
} else if (q = 11) {
document.getElementById('december').click() = dec;
}
}
</script>
</head>

<body>
<ul>
<li><a id="january" href="#" onclick="jan()">January</a></li>
<li><a id="february" href="#" onclick="feb()">February</a></li>
<li><a id="march" href="#" onclick="mar()">March</a></li>
<li><a id="april" href="#" onclick="apr()">April</a></li>
<li><a id="may" href="#" onclick="may()">May</a></li>
<li><a id="june" href="#" onclick="jun()">June</a></li>
<li><a id="july" href="#" onclick="jul()">July</a></li>
<li><a id="august" href="#" onclick="aug()">August</a></li>
<li><a id="september" href="#" onclick="sep()">September</a></li>
<li><a id="october" href="#" onclick="oct()">October</a></li>
<li><a id="november" href="#" onclick="nov()">November</a></li>
<li><a id="december" href="#" onclick="dec()">December</a></li>
</ul>
<iframe sandbox="" allowfullscreen frameborder="0" class="sched"></iframe>
</body>

</html>

最佳答案

第一个错误

使用比较作为 == 而不是 =

第二个错误

var d = new Date();var q = d.getMonth(); 在函数内部使用但从未调用。

第三个​​错误

数组索引 从零开始 所以从 011

<!DOCTYPE html>
<html>

<head>
<meta http-equiv="refresh" content="60" />
<style>
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}

li {
float: left;
font-family: tahoma;
}

li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}

li a:hover {
background-color: #111;
}

#title {
background-color: #333;
border-right: 1px black dotted;
}

iframe {
width: 100%;
height: 1200px;
}
</style>

<script type="text/javascript">
window.onload = function() {
var d = new Date();
var q = d.getMonth();

function jan() {
document.querySelector(".sched").setAttribute("src", "jan.htm")
}

function feb() {
document.querySelector(".sched").setAttribute("src", "feb.htm")
}

function mar() {
document.querySelector(".sched").setAttribute("src", "mar.htm")
}

function apr() {
document.querySelector(".sched").setAttribute("src", "apr.htm")
}

function may() {
document.querySelector(".sched").setAttribute("src", "may.htm")
}

function jun() {
document.querySelector(".sched").setAttribute("src", "jun.htm")
}

function jul() {
document.querySelector(".sched").setAttribute("src", "jul.htm")
}

function aug() {
document.querySelector(".sched").setAttribute("src", "aug.htm")
}

function sep() {
document.querySelector(".sched").setAttribute("src", "sep.htm")
}

function oct() {
document.querySelector(".sched").setAttribute("src", "oct.htm")
}

function nov() {
document.querySelector(".sched").setAttribute("src", "nov.htm")
}

function dec() {
document.querySelector(".sched").setAttribute("src", "dec.htm")
}

document.getElementsByTagName("a")[0].onclick = jan;
document.getElementsByTagName("a")[1].onclick = feb;
document.getElementsByTagName("a")[2].onclick = mar;
document.getElementsByTagName("a")[3].onclick = apr;
document.getElementsByTagName("a")[4].onclick = may;
document.getElementsByTagName("a")[5].onclick = jun;
document.getElementsByTagName("a")[6].onclick = jul;
document.getElementsByTagName("a")[7].onclick = aug;
document.getElementsByTagName("a")[8].onclick = sep;
document.getElementsByTagName("a")[9].onclick = oct;
document.getElementsByTagName("a")[10].onclick = nov;
document.getElementsByTagName("a")[11].onclick = dec;
debugger;
if (q == 0) {
document.getElementById('january').click() = jan;
} else if (q == 1) {
document.getElementById('february').click() = feb;
} else if (q == 2) {
document.getElementById('march').click() = mar;
} else if (q == 3) {
document.getElementById('april').click() = apr;
} else if (q == 4) {
document.getElementById('may').click() = may;
} else if (q == 5) {
document.getElementById('june').click() = jun;
} else if (q == 6) {
document.getElementById('july').click() = jul;
} else if (q == 7) {
document.getElementById('august').click() = aug;
} else if (q == 8) {
document.getElementById('september').click() = sep;
} else if (q == 9) {
document.getElementById('october').click() = oct;
} else if (q == 10) {
document.getElementById('november').click() = nov;
} else if (q == 11) {
document.getElementById('december').click() = dec;
}
}
</script>
</head>

<body>
<ul>
<li><a id="january" href="#" onclick="jan()">January</a></li>
<li><a id="february" href="#" onclick="feb()">February</a></li>
<li><a id="march" href="#" onclick="mar()">March</a></li>
<li><a id="april" href="#" onclick="apr()">April</a></li>
<li><a id="may" href="#" onclick="may()">May</a></li>
<li><a id="june" href="#" onclick="jun()">June</a></li>
<li><a id="july" href="#" onclick="jul()">July</a></li>
<li><a id="august" href="#" onclick="aug()">August</a></li>
<li><a id="september" href="#" onclick="sep()">September</a></li>
<li><a id="october" href="#" onclick="oct()">October</a></li>
<li><a id="november" href="#" onclick="nov()">November</a></li>
<li><a id="december" href="#" onclick="dec()">December</a></li>
</ul>
<iframe sandbox="" allowfullscreen frameborder="0" class="sched"></iframe>
</body>

</html>

关于Javascript - 加载当前月份 htm - 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45800438/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com