简体   繁体   English

提交后隐藏div

[英]Hide div after submit

What is wrong with my code? 我的代码出了什么问题?

After clicking the button, I want to hide and show a div with another result. 单击按钮后,我想隐藏并显示另一个结果的div

This is happening, but is not running the submit code. 这种情况正在发生,但没有运行提交代码。 The field value is not getting propagated. 字段值未传播。

$(document).ready(function(){
    $('#conteudo').hide();

    $('#button').click(function(event){

        $('form#form1').submit(function(event){
            $("#form").hide("slow");
            $("#conteudo").show("slow"); 
            event.preventDefault();
        });

    });


    $('#mostrar').click(function(event){
        event.preventDefault();
        $("#form").show("show");
        $("#conteudo").hide("show");
    });
});

http://api.jquery.com/submit/ says: http://api.jquery.com/submit/说:

...so we can cancel the submit action by calling .preventDefault() on the event object or by returning false from our handler. ...所以我们可以通过在事件对象上调用.preventDefault()或从我们的处理程序返回false来取消提交操作。 ... ...

You should remove the preventDefault() 你应该删除preventDefault()

Unable to do. 无法做到。 If a friend has the same problem solved in this way. 如果朋友以这种方式解决了同样的问题。

$(document).ready(function(){
    $('#conteudo').hide();

    <?php if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { ?>
            $(document).ready(function(){ 
                event.preventDefault(); 
                $("#form").hide("slow"); 
                $("#conteudo").show("slow"); 
            });
    <?php } ?>

    $('#mostrar').click(function(event){
        event.preventDefault();
        $("#form").show("show");
        $("#conteudo").hide("show");
    });
});

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

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