javascript - 如何在提交 JavaScript 后关闭模态

标签 javascript html css window modalviewcontroller

我正在尝试学习 JavaScript 我制作了我的测验游戏。 我遇到模态窗口的问题,因为当我在此之后写昵称时,我按下提交我想在 localStorage 中保存昵称并关闭模态窗口。 问题是模式窗口再次出现,我无法通过测验传递到主页。 也许有人可以向我解释如果可能的话用 JavaScript 以不同的方式做到这一点,起初我想对文档 HTML 做一个 index.html 和 nickname.html ,但我也遇到了问题,因为我不知道如何更改网址();提交后在 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,0);
    background-color: rgb(0,0,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, 0, 0.267);
    box-shadow: 1.5px 1.5px rgba(0, 0, 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>

最佳答案

感谢大家,我找到了解决问题的方法。

在标签内我写了 action 和 url();第二个 HTML 页面。

<form action="secondHtml.html"> 

提交后我转到主页。

关于javascript - 如何在提交 JavaScript 后关闭模态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58737868/

相关文章:

html - 选择特定类别中的所有标签

css - drupal - 如何在 View 模块中为每种网格格式添加自定义 CSS?

javascript - 我正在尝试通过验证创建此登录/注册表单

html - 使用带类的第 nth-child 匹配元素

javascript - 如何使用 Jest 成功模拟和捕获错误?

javascript - Mongodb,如何对1个对象进行多个请求

html - 在 anchor 中垂直对齐跨度时结果不一致,HTML5 与 XHTML

html - Jasny bootstrap 手机不工作

Javascript 计时器和 Ajax 轮询/调度

javascript - JS/CSS onmouseover 问题 - 闪烁