总结后隐藏的简单形式

时间:2015-06-02 17:37:50

标签: javascript html

正如标题所说。当您提交表格消息一秒钟并重新加载浏览器后再次显示。 CSS是一团糟,我正在努力解决问题。

<div id="new_user_form" 
    style="
        width: 400px;
        height: 200px; 
        background-color: grey;">
    <form onsubmit="hide_show()" style="display: block;
    margin: 0 auto; 
        width: 100%;">
        New Nickname: <input type="text" required><br>
        New Password: <input type="password" required>
        <br><input type="submit">
    </form>
</div>

<script>
    function hide_show(){
        document.getElementById("new_user_form").style.display="none";

    }
</script>

1 个答案:

答案 0 :(得分:0)

如果您想提交表单并在提交成功后将其隐藏起来而不刷新页面,那么您应该通过AJAX提交。

一个信息性的例子:https://scotch.io/tutorials/submitting-ajax-forms-with-jquery

基本上你通过AJAX提交表单,当请求成功时 - 你将表单隐藏起来。