【问题标题】:How to close modal after submit JavaScript提交 JavaScript 后如何关闭模式
【发布时间】:2019-11-06 20:17:12
【问题描述】:

我尝试学习 JavaScript 我制作了我的测验游戏。 我遇到了模态窗口的问题,因为当我在此之后写昵称时,我推送提交我想在 localStorage 中保存昵称并关闭模态窗口。 问题是模式窗口再次出现,我无法通过测验传递到主页。 也许有人可以向我解释是否可以在 JavaScript 中以不同的方式执行此操作,起初我想将 HTML 文档设为 index.html 和昵称.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>

【问题讨论】:

    标签: javascript html css window modalviewcontroller


    【解决方案1】:

    感谢大家为我的问题找到解决方案。

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

    <form action="secondHtml.html"> 
    

    提交后我进入主页。

    【讨论】:

      猜你喜欢
      • 2020-11-26
      • 2015-09-23
      • 2015-06-27
      • 2018-08-20
      • 2012-08-14
      • 1970-01-01
      • 2018-07-15
      • 1970-01-01
      • 2017-07-15
      相关资源
      最近更新 更多