我有种从互联网而不是一个班级获得所有编码信息,某些答案我不能真正理解,所以希望我会得到一个简单的答案,可能是一个愚蠢的问题。我是否使用window.location.replace对不对? (也是我写的命令是否正确?)
在我的网站的一部分,我有一个按钮,它会出现一个window.prompt,它会询问观众是否想要转到一个页面(我称它为Timeline,因为它的时间轴是我的艺术作品)或其他。提示符工作得很好,我试图编写代码,例如,如果用户在“时间轴”中键入,网页会自动将它们重定向到时间轴页面(此时对我而言是空的),反之亦然他们键入“术语1”(另一页的名称)。我发现了关于window.location.replace并假设它会工作,如果我试图让它重定向用户,但是当我运行我的网页时什么也没有发生我输入提示窗口后。我在Chrome浏览器上查看了开发者工具,但没有报告任何错误,所以只是我输入了一些错误的东西?
function promptFunction() {
var choice = window.prompt ("Would you like to go to the Timeline or to Term 1?")
if (choice === "Timeline")
function redirTime() {
window.location.replace() ("Timeline.html");
}
else if (choice ==="timeline")
function redirTime() {
window.location.replace() ("Timeline.html");
}
else if (choice ==="Term 1")
function redirFirstTerm() {
window.location.replace() ("Term 1.html")
}
else if (choice ==="term 1")
function redirFirstTerm() {
window.location.replace() ("Term 1.html")
}
};
这又可能是我寻找一个答案没错,我的鼻子底下,所以如果答案是显而易见的事,对不起^^”
编辑:我有一个答案现在;非常感谢你! (我确实认为这与我输入它的方式有关,对不起)