gpt4 book ai didi

指向当前星期几的 JavaScript 代码(day.html,例如 mon.html、tue.html 等)

转载 作者:行者123 更新时间:2023-12-03 10:05:26 26 4
gpt4 key购买 nike

我有一个“继续”按钮,可以引导到一周中的某一天(周日-周六),我希望该按钮使用 javascript 引导到一周中的当前一天,我的网站 dundaah.com到目前为止我已经

<script type="text/javascript">
function myFunction() {
var d = new Date();
var links = new Array(7);
links[0] = "docs/sun.html"
links[1] = "docs/mon.html"
links[2] = "docs/tue.html"
links[3] = "docs/wed.html"
links[4] = "docs/thur.html"
links[5] = "docs/fri.html"
links[6] = "docs/sun.html"

var n = links[d.getDay()];
window.location=links[myFunction]
}
</script>

最佳答案

尝试这样的事情:

<script>
function myFunction() {
var days = ["sun","mon","tue","wed","thur","fri","sat"];
window.location = days[new Date().getDay()] + ".html";
}
</script>

<button type="button" onclick="myFunction()">Today's Link</button>

关于指向当前星期几的 JavaScript 代码(day.html,例如 mon.html、tue.html 等),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30382382/

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