提交JavaScript后如何关闭模式

我尝试学习JavaScript,并制作了Quiz游戏。 我在模态窗口中遇到问题,因为在此后我按下“提交”后再写昵称时,我想将昵称保存在localStorage中并关闭模态窗口。 问题是模式窗口再次出现,我无法通过测验传递到主页。 也许有人可以解释我是否可以在JavaScript中用不同的方式做到这一点,起初我想将文档HTML制作为index.html和nickname.html,但是我也遇到了问题,因为我不知道如何更改url();在提交后使用JavaScript。 我感谢每一个意见。谢谢。

const enter = document.getElementById('enter');
const modal = document.getElementById('screen');

enter.addEventListener('click',function(){
    let forms =  document.forms["form-welcome"]["nickname"].value

    if(forms == ""){
        alert("Write you nickname.");
        return false;
    }
    else{
        modal.style.display = "none";
        save();
        
    }
})
    function save(){
        localStorage.setItem(
            document.forms["form-welcome"]["nickname"].value
    
            );
    }
*{
    margin: 0px;
    padding: 0px;

}
body{
    background-color: red;
}
/*#####  Window Modal  #####*/
.wrapper{
    
    font-size: 24px;
    font-family:'Bree Serif',serif;
    text-align: center;

}
.modal{
    display: block;
    position: fixed;
    z-index: 1;
    left: 0;
    top:0;
    width:100%;
    height: 100%;
    overflow: auto;
    background-color: rgb(0,0);
    background-color: rgb(0,0.4);
}
.offModal{
    display: none;
}
.animate{
    -webkit-animation: animatezoom 0.6s;
    animation: animatezoom 0.6s;
}
.model{
    display: inline-block;
    margin-top: 25px;
    width: 30%;
    height: auto;
    background-color: #4edb0cfb;
    position: relative;
    border-radius: 25px;
    border:1px solid rgba(0,0.267);
    box-shadow: 1.5px 1.5px rgba(0,0.4);
    
}

.welcome{
    letter-spacing: 1px;
    position: relative;
    text-align: center;
    line-height: 50px;
    padding-top: 15px;
    margin-top: 15px;

}
.submit{
    border-radius: 5px;
    font-size: 30px;
    margin: 10px;
    padding: 10px;
}
.submit:hover{
    background-color: rgb(153,150,150);

}
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>Final-Quiz</title>
    <link rel="stylesheet" href="reset.css">
    <link rel="stylesheet" href="style.css">
    <link href="https://fonts.googleapis.com/css?family=Bree+Serif&display=swap" rel="stylesheet">

</head>

<body>
    <div class="wrapper">

        <!--###############    FIST SCREEN    ################-->
        <section>
            <div id="screen" class="modal">
                <form class="welcome model" name="form-welcome">
                    <h1>Final-Quiz</h1>
                    <label for="nickname">Nickname:</label>
                    <input type="text" name="nickname" required>
                    <input id="enter" class="submit" type="submit" value="Enter">
                    <p>Let's check your knowledge about HTML,CSS and JavaScript.</p>

                </form>
            </div>
    </div>

    </section>
    </div>
    <script src="localStorage.js"></script>
</body>

</html>

liuzuowei521 回答:提交JavaScript后如何关闭模式

感谢所有为我的问题找到解决方案的人。

内部标记我写动作和url();第二个HTML页面。

<form action="secondHtml.html"> 

提交后,我进入主页。

本文链接:https://www.f2er.com/3149188.html

大家都在问