[英]How to redirect to another html file in the same directory which is located inside a folder using js?
here's the index.html这是 index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<form id="form-marksheet">
<div class="name">
<p>Name</p>
<input type="text">
</div>
<div class="roll-no">
<p>Roll No.</p>
<input type="text">
</div>
<div class="subject-english">
<p>Marks for English</p>
<input type="text">
</div>
<div class="subject-science">
<p>Marks for Science</p>
<input type="text">
</div>
<div class="subject-math">
<p>Marks for math</p>
<input type="text">
</div>
<div class="btn-trigger-update">
<button onclick="updateScreen()">Get your marksheet</button>
</div>
</form>
<script src="script.js"></script>
</body>
</html>
and the js file和js文件
// Global variables
const student_name = document.getElementById("name")
const roll_no = document.getElementById("roll-no")
const english = document.getElementById("subject-english")
const science = document.getElementById("subject-science")
const math = document.getElementById("subject-math")
// Functions
function updateScreen() {
}
so when updateScreen is called, basically when the get your marksheet
is pressed, i want to redirect to another file called ms.html which is in the same directory as the index.html.因此,当调用 updateScreen 时,基本上当按下
get your marksheet
的标记表时,我想重定向到另一个名为 ms.html 的文件,该文件与 index.html 位于同一目录中。 And yes, this all things are in a folder called input-page
.是的,这一切都在一个名为
input-page
的文件夹中。 I have tried location.href = "ms.html"
, location.assign(ms.html)
.我试过
location.href = "ms.html"
, location.assign(ms.html)
。 Both of them don't work.他们两个都不工作。 Can anyone show me how to redirect to another html file using js?
谁能告诉我如何使用 js 重定向到另一个 html 文件?
and here's style.css too这里也是 style.css
/* Font imports */
@import url('https://fonts.googleapis.com/css2?family=Anek+Latin:wght@600&family=Kanit:wght@300&family=Open+Sans&family=PT+Sans&family=Poppins:wght@300;500&family=Roboto+Mono:wght@700&family=Smooch+Sans:wght@300;900&family=Source+Sans+Pro&display=swap');
/* Styling */
* {
margin: 0;
overflow: hidden;
font-family: 'Poppins', sans-serif;
}
html, body { height: 100%; }
body {text-align: center;}
form {display: inline-block;}
this isn't required, but I gave anyways.这不是必需的,但我还是给了。
You should be able to do it using:您应该能够使用:
window.location.href = "ms.html";
Here is a reference to a similar article with more details: Jumping to a new HTML page with JavaScript这是对类似文章的参考,其中包含更多详细信息: Jumping to a new HTML page with JavaScript
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.