Change submit button to a loading image with jquery

后端 未结 9 1122
庸人自扰
庸人自扰 2021-02-06 11:12

On a lot of sites lately, I\'ve seen buttons being replaced with loading/thinking images after they are pressed, to prevent double clicks and make sure the user knows something

9条回答
  •  星月不相逢
    2021-02-06 11:41

    Although simply replacing the submit with an image might work, removing the button might prevent the submit input's value from being sent (like when it's disabled). This can cause problems for some applications that rely on the submit's value being sent to the server - for example testing which submit button the user has pressed or using the same controller for many actions.

    For those cases, you can use another method that works just as good - hiding the submit and adding an image:

    $(document).ready(function() {
        $('input[type="submit"]').click(function() {
            $(this).css('display', 'none');
            $('').attr('src', 'http://www.mayla.ro/App_Themes/Glass/Editors/Loading.gif').insertAfter($(this));
        });
    });
    

提交回复
热议问题