简体   繁体   English

如何使用js重定向到位于文件夹内的同一目录中的另一个html文件?

[英]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.

相关问题 如何使用javascript读取与html位于同一目录中的本地文件 - How to read local file that in located in the same directory as html using javascript 如何在 electron JS 文件中导入另一个 JS 文件(位于同一目录中) - How can I import another JS file (which is in the same directory) in a electron JS file 如何在不使用XMLHttpRequest()的情况下读取与index.html位于同一目录中的文本文件<input type=“file” id=“fileToLoad”> - How do I read a text file located in the same directory as my index.html using XMLHttpRequest() without using <input type=“file” id=“fileToLoad”> 如何从index.html加载我的Aurelia应用,该索引与应用的其余部分不在同一文件夹中? - How can I load my Aurelia app from an index.html which is not located in the same folder as the rest of the application? 使用javascript重定向到同一文件夹中的另一个页面 - Redirect to another page in same folder using javascript 如何使用 express.js 发送另一个文件夹中的文件? - how can I send a file that's inside another folder using express.js? 如何为位于数组内的值创建按钮,而同一数组位于另一个数组内? - how can I create buttons for values located inside an array, and that same array is located inside another array? 如何加载位于同一路径的JSON文件? - How to load a JSON file which is located in the same path? 如何使用JS加载另一个html文件 - How to load another html file using JS 如何获取存储在应用程序包中的javascript文件(JS)路径到文档目录中存在的html文件 - How to get the javascript file (JS) path which is stored in application bundle to html file which is there in document directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM