Form doesn't move up on submit

后端 未结 3 876
粉色の甜心
粉色の甜心 2021-01-24 05:59

I\'m trying to move the form up a few pixels and this doesn\'t work. I don\'t know why.

The function is being called when I submit (I have tested it with an alert()), bu

3条回答
  •  清酒与你
    2021-01-24 06:18

    You are using css top without any position properties. Try using position absolute or relative

    $(document).ready(function () {
                $("#formulario").submit(function (event) {
                    $(this).css({
                        top: '-50px',
                        position: 'relative'
                    });
                });
            });
    

    If you do not wish to change the position property, you can modify the margin-top property like

    $(document).ready(function () {
                    $("#formulario").submit(function (event) {
                        $(this).css({
                            marginTop: '-50px'
                        });
                    });
                });
    

    Finally, note that when a form submits, the page reloads so you will most likely only see this change temporarily. If you return false, the page will not reload(although this may not be what you want)

    $(document).ready(function () {
                        $("#formulario").submit(function (event) {
                            $(this).css({
                                marginTop: '-50px'
                            });
                            return false;
                        });
                    });
    

提交回复
热议问题