繁体   English   中英

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

[英]How to redirect to another html file in the same directory which is located inside a folder using js?

这是 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>

和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() {
    
}

因此,当调用 updateScreen 时,基本上当按下get your marksheet的标记表时,我想重定向到另一个名为 ms.html 的文件,该文件与 index.html 位于同一目录中。 是的,这一切都在一个名为input-page的文件夹中。 我试过location.href = "ms.html"location.assign(ms.html) 他们两个都不工作。 谁能告诉我如何使用 js 重定向到另一个 html 文件?

这里也是 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;}

这不是必需的,但我还是给了。

您应该能够使用:

window.location.href = "ms.html";

这是对类似文章的参考,其中包含更多详细信息: Jumping to a new HTML page with JavaScript

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM